如何增加数量上的SQL Server列
问题描述:
HY那里我有这样如何增加数量上的SQL Server列
name | phone | emp_pin
-----------------------
anton1 |12345 | null
budi |12345 | null
santoso|12345 | null
hendri |12345 | null
的记录,我有声明变量
set @nik_temp = (select [Pin_Number] from [Pin_Number_Seq])
set @total = (select count name from emptable)
我如何做到这一点
name | phone | emp_pin
-----------------------
anton1 |12345 | 100001
budi |12345 | 100002
santoso|12345 | 100003
hendri |12345 | 100004
我尝试使用虽然,但它使记录成为重复
答
您可以使用ROW_NUMBER如下:
Select [Name], [Phone],
emp_pin = 100000 + Row_Number() over(order by [Name])
from emptable
+1
谢谢你,多数民众赞成在帮助我很多 – Rommy
答
尝试这样做
create table emptable(
name varchar(400),
phone int(11),
emp_pin int(16) auto_increment,
PRIMARY KEY (emp_pin)
)
ALTER TABLE emptable AUTO_INCREMENT=100001;
emp_pin是序列号或邮政编码,你正试图从不同的表拉? –