SQL 主键 自动编号 主键自增
生活随笔
收集整理的這篇文章主要介紹了
SQL 主键 自动编号 主键自增
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1.新建一數據表,里面有字段id,將id設為為主鍵
代碼如下: create table tb(id int,constraint pkid primary key (id)) create table tb(id int primary key )2.新建一數據表,里面有字段id,將id設為主鍵且自動編號
代碼如下: create table tb(id int identity(1,1),constraint pkid primary key (id)) create table tb(id int identity(1,1) primary key )3.已經建好一數據表,里面有字段id,將id設為主鍵
代碼如下: alter table tb alter column id int not nullalter table tb add constraint pkid primary key (id)
4.刪除主鍵
代碼如下: 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)轉載于:https://www.cnblogs.com/swtool/p/3794820.html
與50位技術專家面對面20年技術見證,附贈技術全景圖總結
以上是生活随笔為你收集整理的SQL 主键 自动编号 主键自增的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: MONO Design创建电信3D机房
- 下一篇: 网络知识要点