34,597
社区成员
发帖
与我相关
我的任务
分享
--> 测试数据:[m]
if object_id('[m]') is not null drop table [m]
go
Create table m
( ID int not NULL ,
cno int not NULL ,
pno int not null,
pname varchar(10) not null
)
INSERT into m(id , cno, pno,pname )
SELECT 1,111,11,'名称1' UNION ALL
SELECT 2,111,11,'名称2' UNION ALL
SELECT 3,111,11,'名称3' UNION ALL
SELECT 3,112,12,'名称4' UNION ALL
SELECT 3,112,13,'名称5'
--操作
INSERT into m(id , cno, pno,pname )
select id , 999, pno,pname from m --999位新值
where cno=111
select * from m
drop table m
/*
(5 行受影响)
(3 行受影响)
ID cno pno pname
----------- ----------- ----------- ----------
1 111 11 名称1
2 111 11 名称2
3 111 11 名称3
3 112 12 名称4
3 112 13 名称5
1 999 11 名称1
2 999 11 名称2
3 999 11 名称3
(8 行受影响)
*/
--是要把111的改成新的值么?
update tb set cno ='新的值' from tb where cno ='111'