Default SQL primary key ID

Source: Internet
Author: User
Tags sql primary key

 

Set identity_insert [DBO]. [t_message] oninsert into [DBO]. [t_message] (f_mid) values (55)
Set identity_insert [DBO]. [t_message] offgoselect * from [DBO]. [t_message] order by f_mid DESC identify sequence DBCC checkident ('t_member ', reseed, @ identity)

Primary Key

View code

select name from sysobjects where parent_obj=object_id('abc') and  xtype='pk'alter table abc add constraint PK_bbb primary key(bbb)alter table abc drop constraint PK_bbb

 

Id Modification

View code

Four steps: 1. Add an int-type alter table add xinglie Int. 2. Update the data in the new column to the auto-incrementing column. Update TB set xinglie = auto-incrementing column name. 3. Delete the auto-incrementing column alter table tb. drop column auto-incrementing column 4. Change the new column name to the original auto-incrementing column name exec sp_rename n'tb. xinglie ', 'original auto-incrementing column name', n' column'

Default Value

-- Note: alter table abc drop constraint df_bbb, the original constraint for deleting table fields -- Note: add a table field constraint and specify the default value alter table abc add constraint df_ccc default 5 for CCC -- the default value of the table field select B. text as DF from syscolumns a left join syscomments B on. cdefault = B. ID where. id = object_id ('abc') and. name = 'ccc '-- constraints on the default values of the query table fields select B. name,. * From sysobjects A, syscolumns bwhere. id = B. cdefault and. parent_obj = object_id ('abc') and. xtype = 'D' and B. name = 'ccc'

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.