欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

SQL Server設(shè)置主鍵自增長列(使用sql語句實現(xiàn))

 更新時間:2013年01月24日 16:47:53   作者:  
主鍵自增長列在進行數(shù)據(jù)插入的時候,很有用的,如可以獲取返回的自增ID值,接下來將介紹SQL Server如何設(shè)置主鍵自增長列,感興趣的朋友可以了解下,希望本文對你有所幫助
1.新建一數(shù)據(jù)表,里面有字段id,將id設(shè)為為主鍵
復(fù)制代碼 代碼如下:

create table tb(id int,constraint pkid primary key (id))
create table tb(id int primary key )

2.新建一數(shù)據(jù)表,里面有字段id,將id設(shè)為主鍵且自動編號
復(fù)制代碼 代碼如下:

create table tb(id int identity(1,1),constraint pkid primary key (id))
create table tb(id int identity(1,1) primary key )

3.已經(jīng)建好一數(shù)據(jù)表,里面有字段id,將id設(shè)為主鍵
復(fù)制代碼 代碼如下:

alter table tb alter column id int not null
alter table tb add constraint pkid primary key (id)

4.刪除主鍵
復(fù)制代碼 代碼如下:

Declare @Pk varChar(100);
Select @Pk=Name from sysobjects where Parent_Obj=OBJECT_ID('tb') and xtype='PK';
if @Pk is not null
exec('Alter table tb Drop '+ @Pk)

相關(guān)文章

最新評論