Adding an auto-incrementing column ID to an existing table and assigning values to the table already contains a lot of data.
Stored Procedure
Declare @ ID int
Declare @ name varchar (500)
Declare Taba cursor
Select export database1.dbo. ggxxkc. ID, export database1.dbo. ggxxkc. syzy
From export database1.dbo. ggxxkc
Open Taba
Fetch next from Taba into @ ID, @ name
While (@ fetch_status = 0)
Begin
Update your database. DBO. ggxxkc set your database. DBO. ggxxkc. syzybh = @ name where your database. DBO. ggxxkc. ggxxkcid = @ ID
Fetch next from Taba into @ ID, @ name
End
Close Taba
Deallocate Taba
You can also compileProgram
Using system;
Using system. Collections. Generic;
Using system. componentmodel;
Using system. Data;
Using system. Data. sqlclient;
Using system. drawing;
Using system. text;
Using system. Windows. forms;
Namespace windowsformsapplication1
{
Public partial class form1: Form
{
Public form1 ()
{
Initializecomponent ();
}
Private void button#click (Object sender, eventargs E)
{
String STR = @ "Server = 211.85.185.5; user id = sa; Password =; database = newjwc; Connect timeout = 500;
Min pool size = 4; Max pool size = 4; packet size = 3072 ";
Sqlconnection conn = new sqlconnection (STR );
Conn. open ();
String sql1 = "select * From xjbd ";
Sqldataadapter Ada = new sqldataadapter (sql1, Conn );
Dataset DS = new dataset ();
Ada. Fill (DS );
Int id = 1;
Foreach (datarow DR in DS. Tables [0]. Rows)
{
String sql2 = @ "Update xjbd Set ID =" + id. tostring () + "where xsid =" + Dr ["xsid"]. tostring () + "and xbh = '"
+ Dr ["xbh"]. tostring () + "'";
Sqlcommand comm = new sqlcommand (sql2, Conn );
Comm. executenonquery ();
Id ++;
}
}
}
Run it.