将列添加到现有表,并对其进行唯一编号(Add a column to existing table and uniquely number them)
我想向现有的遗留数据库添加一列,并写入一个过程,通过该过程,我可以为每个记录分配一个不同的值。 像添加列并自动生成数据。
喜欢,如果我添加一个名为“ID”(数字)的列,我想要为每个记录初始化一个唯一的值。 所以,我的ID列将记录从1到1000.我该怎么做?
I want to add a column to an existing legacy database and write a procedure by which I can assign each record a different value. Something like add a column and autogenerate the data for it.
Like, if I add a new column called "ID" (number) I want to then initialize a unique value to each of the records. So, my ID column will have records from say 1 to 1000. How do I do that?
最满意答案
这将取决于数据库,但对于SQL Server,可以如下实现:
alter table Example add NewColumn int identity(1,1)This will depend on the database but for SQL Server, this could be achieved as follows:
alter table Example add NewColumn int identity(1,1)更多推荐
发布评论