MSSQL 學習筆記

Add a auto_increment primary key

ALTER TABLE MyTable ADD mytableID int NOT NULL IDENTITY (1,1) PRIMARY KEY
More precisely to set a named table level constraint
ALTER TABLE MyTable ADD MytableID int NOT NULL IDENTITY (1,1), ADD CONSTRAINT PK_MyTable PRIMARY KEY CLUSTERED (MyTableID)

Sha1()

sys.fn_varbintohexsubstring(0, HashBytes('SHA1', '1234561'), 1, 0) 

Alter

Add Column

ALTER TABLE dbo.YourTable ADD ID INT IDENTITY
ALTER TABLE dbo.YourTable ADD CONSTRAINT PK_YourTable PRIMARY KEY(ID)

Change Column Type

ALTER TABLE table_name
ALTER COLUMN column_name datatype

Key

Get all key with column_name

select * From INFORMATION_SCHEMA.KEY_COLUMN_USAGE where column_name=’column_name’

Drop specify key

 

alter table table_name drop constraint  PK_xxx;

Drop Table

DELETE FROM [arcas].[dbo].[flm_order];
DBCC CHECKIDENT ('arcas.dbo.[flm_order]',RESEED, 0)

分頁

有排序,又稱【夾擠式分頁查詢】。MS-SQL 2000以前,常見的分頁用語法。

SELECT * FROM 
(
    SELECT TOP [每頁長度] * FROM 
    (
        SELECT TOP [每頁長度*第幾頁] [欄位1, 欄位2, ...] 
        FROM [資料表]
        WHERE [篩選條件]     
        ORDER BY [排序欄位] [DESC/ASC]
    )
    AS [資料表别名1]
    ORDER BY [排序欄位] [ASC/DESC]
)
AS [資料表别名2] 
ORDER BY [排序欄位] [DESC/ASC]

 

無排序,在關聯式查詢時,可能導致每次查詢同一分頁的資料時,出來的資料都不一樣。

SELECT [欄位1, 欄位2, ...] FROM [資料表]
    WHERE [主要索引欄位] IN
    (
        SELECT * FROM 
        (
            SELECT TOP [每頁長度*第幾頁] [主要索引欄位]
                FROM [資料表]
                WHERE [篩選條件]     
        )
        AS [資料表别名1]
        WHERE [主要索引欄位] NOT IN
        (
            SELECT TOP [每頁長度] [主要索引欄位] 
                FROM [資料表]
                WHERE [篩選條件] 
        )
    )

 

MS-SQL 2005以後才有RANK()語法。

SELECT * FROM 
(
    SELECT rank() OVER ( ORDER BY [排序欄位] [ASC/DESC] ) AS RankNumber, * FROM
    (
        SELECT [欄位1, 欄位2, ...] 
        FROM [資料表]
        WHERE [篩選條件]     
    )
    AS [資料表别名1]
) AS [資料表别名2]
WHERE RankNumber between [每頁長度*(第幾頁-1)] and [每頁長度*第幾頁]

 

MS-SQL 2000可用,但Select時,不可包含PK用的欄位。(需透過暫存資料表操作)

SELECT IDENTITY(INT,1,1) AS RankNumber, [欄位1, 欄位2, ...] 
INTO [#暫存資料表名稱] 
FROM [資料表]
ORDER BY [排序欄位] [ASC/DESC];
 
SELECT * FROM [#暫存資料表名稱]
WHERE RankNumber between [每頁長度*(第幾頁-1)] and [每頁長度*第幾頁];
 
DROP TABLE [#暫存資料表名稱];

MYSQL的LIMIT效果

SQL SERVER 2000

SELECT TOP 10 * FROM (SELECT TOP 20 FROM Table ORDER BY Id) ORDER BY Id DESC

 

( SQL SERVER 2005)

USE AdventureWorks; GO WITH OrderedOrders AS ( SELECT SalesOrderID, OrderDate, ROW_NUMBER() OVER (ORDER BY OrderDate) AS 'RowNumber' FROM Sales.SalesOrderHeader ) SELECT * FROM OrderedOrders WHERE RowNumber BETWEEN 10 AND 20;

linux下使用Letsencrypt為Nginx服務器的網站添加SSL証書

安裝letsencrypt

git clone https://github.com/letsencrypt/letsencrypt /home/username/letsencrypt

生成証書

cd letsencrypt/

./letsencrypt-auto certonly --webroot-path /var/www/xxx.com/ --agree-tos --email [email protected] -d xxx.com -d www.xxx.com -d subdomain1.xxx.com -d subdomain2.xxx.com -d subdomain3.xxx.com

#key會存在/etc/letsencrypt/live/domain_name

Nginx setting

編輯nginx的site配置文件

添加以下的並保存

ssl on;
ssl_certificate /etc/letsencrypt/live/xxx.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/xxx.com/privkey.pem;

重啟Ngnix

service ngnix restart

算法學習筆記—Binary search 二進制搜索

  1. Let min = 0 and max = n-1.
  2. If max < min, then stop: target is not present in array. Return -1.
  3. Compute guess as the average of max and min, rounded down (so that it is an integer).
  4. If array[guess] equals target, then stop. You found it! Return guess.
  5. If the guess was too low, that is, array[guess] < target, then set min = guess + 1.
  6. Otherwise, the guess was too high. Set max = guess – 1.
  7. Go back to step 2.

線性搜索 的猜測次數是2^(數組長度+1)次

var doSearch = function(array, targetValue) {
var min = 0;
var max = array.length - 1;
var guess; 

while(max&gt;=min){
guess =Math.floor((min+max)/2) ;
if(array[guess]===targetValue){ return guess; }
else if(array[guess]&lt;targetValue){min=guess+1;}
else{ max=guess-1; }
}

return -1;
};

var primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37,
41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97];

var result = doSearch(primes, 73);
println("Found prime at index " + result);

Program.assertEqual(doSearch(primes, 73), 20);
  
  

我没時間討厭你—可可·香奈兒 讀後有感

這是一本時尚女王的回憶錄,
看到這本書時只是略略看了眼,
當看到”只要還有人在思念逝去的那人,那人就不算真的逝去”、
“成功並不會寫在書裏”,
就這兩句話吸引了我繼續看下去.

看這本書就如聽著當年高傲的她在細說自己的故事.
在悲催的童年時她就明白了金錢的重要,
小時的她總響往著出入沙龍的貴婦生活,
並且離家出走為了自己的夢想努力奮斗.
憑著她對時尚的獨特眼光、理念和執著,
從只有六人的帽子店到擁有三千五百人的帝國.
從不敢正面看人的造帽小姑娘而成為傲視上流社會的時尚女王.

她,就是可可·香奈兒.

手工—INGRESS LINK AMP!!

没人指導不懂要買甚麼,在各種猜測下便買了一堆用不上的材料,都可以開手工店了。。所以在這裡做一做司機,說一下材料收集心得

材料如下:
鋼材,我是定制了(外徑5毫米 壁厚1.5毫米 長50毫米 6條 長30毫米 6條 )不過感覺做出來有點大 反正長的和短的比例是5:3就行 想做小一點的可以按這比例計算

https://item.taobao.com/item.htm?spm=a312a.7700846.0.0.mUodL1&id=23310732848&_u=55dvmk20724

定型線(用來做主軸)
一開始不知道要用甚麼東東做主軸,在淘寶搜了一圈才知道有定型銅線這東西
https://item.taobao.com/item.htm?spm=a312a.7700846.0.0.mUodL1&id=7784354905&_u=55dvmk297eb

魚線(穿珠子和鋼條)
魚線我買了彈力款和没彈力的,做時才發現用彈力款的完全是坑爹的.忘了是用0.3MM還是0.5MM,反正便宜多買一筒吧
https://item.taobao.com/item.htm?spm=a312a.7700846.0.0.mUodL1&id=7784069715&_u=55dvmk29c66

珠子
最坑爹的部份..因為不知大小所以買了一堆珠子回來…中間的珠子用了12MM的 但感覺還是有點小 如果有14MM的可以試下 不過我没買TAT..

彩珠子
https://shop104069475.taobao.com/shop/view_shop.htm?spm=a312a.7700846.0.0.mUodL1&user_number_id=1693056020

粉式款的鋼條連接位的珠子用了菠萝珠,
藍色款中間頂著的透明珠是用車輪珠

透明菠萝珠子
https://item.taobao.com/item.htm?spm=a312a.7700846.0.0.mUodL1&id=39011660944&_u=55dvmk2597b

車輪透明珠子
https://item.taobao.com/item.htm?spm=a312a.7700846.0.0.mUodL1&id=18937693003&_u=55dvmk2fb33

一些裝飾:
https://item.taobao.com/item.htm?spm=a312a.7700846.0.0.mUodL1&id=7694444905&_u=55dvmk2f174

https://item.taobao.com/item.htm?spm=a312a.7700846.0.0.mUodL1&id=7694359147&_u=55dvmk2d2c8

https://item.taobao.com/item.htm?spm=a312a.7700846.0.0.mUodL1&id=7694444905&_u=55dvmk2f174

https://item.taobao.com/item.htm?spm=a312a.7700846.0.0.mUodL1&id=7694445707&_u=55dvmk2782c

挂繩
https://item.taobao.com/item.htm?spm=a312a.7700846.0.0.mUodL1&id=41856670993&_u=55dvmk232cf

鎖匙圈
https://item.taobao.com/item.htm?spm=a312a.7700846.0.0.mUodL1&id=526317834134&_u=55dvmk2a314

教程
https://plus.google.com/116781937899591593068/posts/bNkC6XzdmeD