1、創建表時指定標識列 標識列可用 identity 屬性建立,因此在sql server中,又稱標識列為具有identity屬性的列或identity列。 下面的例子創建一個包含名為id,類型為int,種子為1,遞增量為1的標識列 create table t_test (id int identity(1,1), name varchar(50) )
4、查詢某表標識列的列名 sql server中沒有現成的函數實現此功能,實現的sql語句如下 select column_name from information_schema.columns where table_name='表名' and columnproperty( object_id('表名'),column_name,'isidentity')=1
5、標識列的引用
如果在sql語句中引用標識列,可用關鍵字identitycol代替 例如,若要查詢上例中id等于1的行, 以下兩條查詢語句是等價的 select * from t_test where identitycol=1 select * from t_test where id=1