SQL问题,在线等!!

showliz 2004-12-14 12:00:35
怎样用SQL实现:
两个表主ID相同,把一个表的某个字段数据更新另一个表的某个不同名字段同类型的数据.
如:
表user字段:UID和userclass
表Shop_user 字段:SID和usertype
关联:UID=SID
把user表的userclass字段所有数据记录更新到shop_user表的usertype相对应字段中.
在线等,问题解决即给分!
...全文
199 13 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
fog 2004-12-14
  • 打赏
  • 举报
回复
写触发器好了
fenlin 2004-12-14
  • 打赏
  • 举报
回复
就是楼上的方法
showliz 2004-12-14
  • 打赏
  • 举报
回复
谢谢大家的帮助!在下感谢不尽!user是我从Access来的,我也知道有点不好,谢谢各位的指教!但分数有限,我试了 tianch(晴空)成功了!谢谢各位!
devin--- 2004-12-14
  • 打赏
  • 举报
回复
update shop_user set shop_user.usertype=user.userclass from shop_user join [user] on shop_user.uid=[user].sid
试一下这个
yqh1314 2004-12-14
  • 打赏
  • 举报
回复
select userclass from user where shop_user.sid=user.uid

update shop_user set usertype=userclass from shop_user where shop_user.sid=user.uid
wsflyfish 2004-12-14
  • 打赏
  • 举报
回复
#####,另外请注意不要用user来命名表,如果用user例如取数据要写成:select * from [user] 这样用起来麻烦和问题也很多,我觉得从开始就应该养成好的习惯####
是啊!以前我吃过亏!
Kandy 2004-12-14
  • 打赏
  • 举报
回复
上面语句没检验,但是思路是这样的,另外请注意不要用user来命名表,如果用user例如取数据要写成:select * from [user] 这样用起来麻烦和问题也很多,我觉得从开始就应该养成好的习惯
tianch 2004-12-14
  • 打赏
  • 举报
回复
应该这样
update shop_user set shop_user.usertype=user.userclass from shop_user,user where shop_user.sid=user.uid
Kandy 2004-12-14
  • 打赏
  • 举报
回复
在SQL 的查询分析器中建立触发器
create trigger update_yourtable on user for update
--请将表名改成别的在SQL里USER似乎是保留字
as
update Shop_user set shop_user.usertype=user.userclass where sid in(select uid from inserted)


wsflyfish 2004-12-14
  • 打赏
  • 举报
回复
方法一:exists子句
SQL> delete from a where exists (select 'X' from b where a.bm=b.bm and a.mc=b.mc);
where条件:如果两个表中都拥有相同字段的主键(primary key),则只需比较两个主键就可以了
方法二:in子句
SQL> delete from a where (bm,mc) in (select bm,mc from b);
你自己总结吧!这我以前的删除用的!原理差不多!
showliz 2004-12-14
  • 打赏
  • 举报
回复
触发器不知道怎写,还有没有高手能相助的啊?
showliz 2004-12-14
  • 打赏
  • 举报
回复
这个我也想到了,已经试过了,不行啊.
若白师妹 2004-12-14
  • 打赏
  • 举报
回复
update shop_user set shop_user.usertype=user.userclass where shop_user.sid=user.uid

未经测试

28,409

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧