是 1: update 表 set id = 0 where id = 1 还是 2: insert 另一个表(id,其它字段) select 0,其它字段 from 表 where id = 1
把一个表中id=1的列复制为id=0(id 不是该表的关键字)?? 更新吧。 update 表名 set id = 0 where id = 1这行代码可将所有id为1的记录的id更新为0。不知道是不是你想要的结果。
是不是新增一个字段id2,用来纪录!ALTER TABLE 表 ADD id2 int NULL GO update 表 set id2=0 where id=0 go大家都看不大懂你的意思!!
是这样的,把select @name=name from tbl where id=1 得到的记录insert into tbl(id,name) values(0,@name) 表是同一张表,“id”也不是这一张表的关键字,而是外关键字
你用Update语句更新不可以吗,Update tb1 Set id = 0 Where id = 1
insert into tbl(id,name) select '0',name from tb1 where id =1 呵呵!这个结果不知你满意否?
insert 表 (id,其他列) select 0,其他列 from 表 where id=1
insert 另一个表(id) select 0 from 表名 where id = 1
select * into #temptable from table插入到临时表中
--这句就行啦. insert into tb1(id,name) select 0,name from tb1 where id=1
--例子: --数据测试环境 create table tb1(id int,name varchar(10)) insert into tb1 values(1,'aa') insert into tb1 values(1,'bb') insert into tb1 values(2,'aa')--复制 insert into tb1(id,name) select 0,name from tb1 where id=1--显示结果 select * from tb1go --删除测试环境 drop table tb1/*--测试结果 id name ----------- ---------- 1 aa 1 bb 2 aa 0 aa 0 bb(所影响的行数为 5 行) --*/
多谢各位,用 insert into select from 解决, 呵呵,连存储过程都不用写了,真好, 结贴了
1: update 表 set id = 0 where id = 1
还是
2: insert 另一个表(id,其它字段) select 0,其它字段 from 表 where id = 1
更新吧。
update 表名 set id = 0 where id = 1这行代码可将所有id为1的记录的id更新为0。不知道是不是你想要的结果。
GO
update 表 set id2=0 where id=0
go大家都看不大懂你的意思!!
得到的记录insert into tbl(id,name) values(0,@name)
表是同一张表,“id”也不是这一张表的关键字,而是外关键字
呵呵!这个结果不知你满意否?
insert into tb1(id,name) select 0,name from tb1 where id=1
--数据测试环境
create table tb1(id int,name varchar(10))
insert into tb1 values(1,'aa')
insert into tb1 values(1,'bb')
insert into tb1 values(2,'aa')--复制
insert into tb1(id,name) select 0,name from tb1 where id=1--显示结果
select * from tb1go
--删除测试环境
drop table tb1/*--测试结果
id name
----------- ----------
1 aa
1 bb
2 aa
0 aa
0 bb(所影响的行数为 5 行)
--*/
insert into
select
from
解决,
呵呵,连存储过程都不用写了,真好,
结贴了