更新时间:2023-09-24 17:31:58
是的,它是。更新 dst
SET dst.id = src.id
FROM YourTableName AS dst INNER JOIN (
SELE CT ROW_NUMBER() OVER ( ORDER BY [name]) AS id,[name],[address]
) AS src ON dst。[name] = src。[name] AND dst。[address] = src。[地址]
Alter Table RegistrationForm
添加Id_new Int身份(1,1)
Go
Alter Table RegistrationForm Drop Column id
Go
Exec sp_rename'RegistryForm.Id_new','id','Column'
GO
我得到了代码......感谢所有答案。
I have a table with 11 rows variable now i am need in id column and set as primary key and i want to number or auto increment the id column for 11 rows
eg :
id name address
null a b
null c d
.
.
11 records
i want ot output like that
id name address
1 a b
2 c d
.
.
.
11 z f
is there any query to do it...
Yes, it is.UPDATE dst SET dst.id = src.id FROM YourTableName AS dst INNER JOIN ( SELECT ROW_NUMBER() OVER(ORDER BY [name]) AS id, [name], [address] ) AS src ON dst.[name] = src.[name] AND dst.[address] = src.[address]
Note: Insted using query, set IDENTITY[^] property forid
field.
Alter Table RegistrationForm
Add Id_new Int Identity(1, 1)
Go
Alter Table RegistrationForm Drop Column id
Go
Exec sp_rename 'RegistrationForm.Id_new', 'id', 'Column'
GO
I got the code...Thanks for the all the answer.