C#我想把数据库一个表所有复制到另外一个表
发布网友
发布时间:2024-10-03 11:18
我来回答
共3个回答
热心网友
时间:2024-10-03 12:20
insert into A(name,password) select * from B left join A on A.name=B.name where A.name=null;
如果A里面有name重复记录就不插入,如果有就插入
热心网友
时间:2024-10-03 12:12
insert into A select id=identity(int,1,1),[name],[password] from B
热心网友
时间:2024-10-03 12:20
DECLARE @ID varchar(50)
DECLARE @NAME varchar(50)
DECLARE @PASSWORD varchar(50)
DECLARE B_cursor CURSOR FOR
select name from B
OPEN B_cursor
FETCH NEXT FROM B_cursor INTO @NAME
WHILE @@FETCH_STATUS=0
BEGIN
select @PASSWORD=password from B where name = @NAME
SET @ID='要设置的值'
INSERT INTO A(ID,name,password) VALUES(@ID,@NAME,@PASSWORD)
FETCH NEXT FROM B_cursor INTO @NAME
END
CLOSE B_cursor
DEALLOCATE B_cursor
GO