将列添加到现有表,并对其进行唯一编号(Add a column to existing table and uniquely number them)

编程入门 行业动态 更新时间:2024-10-18 21:24:48
将列添加到现有表,并对其进行唯一编号(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)

更多推荐

本文发布于:2023-07-23 18:38:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1235652.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:对其   编号   Add   column   number

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!