首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

怎么更新这样的数据库

2012-03-01 
如何更新这样的数据库现有表A字段a1字符型长度10字段a2字符型默认值0作为标记位表B字段b1字符型长度10表A

如何更新这样的数据库
现有表A
字段   a1   字符型   长度10
字段   a2   字符型   默认值0   作为标记位
表B
字段   b1   字符型   长度10

表A中a1可能有多个相同记录,但不一定能在表B的b1字段中找到对应
表B中b1惟一

现在想将A.a1中能在B.b1中找到对应关系的记录的a2标记位置为1,请问诸位大虾如何写这样的语句,急用,非常感谢

[解决办法]
update A set a2 = 1 from A join B on A.a1 = B.b1
[解决办法]
Update dbo.a
Set a1=1
Where a.a1=b.b1
[解决办法]
update A
set a2 = 1
from A,B
where A.a1 = B.b1,
[解决办法]
create table A(a1 int,a2 int)
insert A select 1,0
union all select 1,0
union all select 1,0
union all select 2,0
union all select 3,0

create table B(b1 int)
insert B select 1
union all select 3
union all select 4

select * from A
select * from B

update A set a2=1 from A where exists ( select * from B where B.b1=A.a1)

select * from A

drop table A,B
[解决办法]
UPDATE A
SET a2 = 1
FROM A,B
WHERE A.a1 = B.b1

热点排行