SQL Server設置主鍵自增長列(使用sql語句實現)建站
導讀:1建站知識主鍵自增長列在進行數據插入的時候,很有用的,如可以獲取返回的自增ID值,接下來將介紹SQL Server如何設置主鍵自增公司網站建設網站seo優化。
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 null alter table tb add constraint pkid prim網站建設多少錢ary key (id)
4.刪除主鍵復制代碼 代碼如下:
Declare @Pk varChar(100); Select @Pk=Name fro網站建設教程m s網站seo優化軟件ysobjects where Parent_Obj=OBJECT_ID('tb') and xtype='PK'; if @Pk is not null exec('Alter table tb Drop '+ @Pk)
相關公司網站建設網站seo優化。聲明: 本文由我的SEOUC技術文章主頁發布于:2023-05-23 ,文章SQL Server設置主鍵自增長列(使用sql語句實現)建站主要講述語句,主鍵,SQL網站建設源碼以及服務器配置搭建相關技術文章。轉載請保留鏈接: http://www.bifwcx.com/article/web_6084.html