开发者

How to change Column Properties In SQL?

开发者 https://www.devze.com 2022-12-09 23:56 出处:网络
I have many tables; each has a primary key which is an Identity column wit开发者_开发问答h a seed of 1.

I have many tables; each has a primary key which is an Identity column wit开发者_开发问答h a seed of 1.

I have another program which converts data from a previous database (dBase) to sql.

This programs needs Indentity = No.

How can I change Identity and Identity Seed from my code?


It sounds like you want to insert values into the IDENTITY column

You can do that using

SET IDENTITY_INSERT TableName ON

INSERT INTO MyTable (IdentityColumn, Column1, Column2) Values (1, 2, 3)

SET IDENTITY_INSERT TableName OFF

Note: you must specify all the column names

To reseed identity (to lets say start at 77) use the following command

dbcc checkident(TableName, RESEED, 77)


There's no need to break the table for the sake of a data import, just do this:

set identity_insert MyTable on

insert into MyTable ... blah blah blah

set identity_insert MyTable off
0

精彩评论

暂无评论...
验证码 换一张
取 消