update的其它用法

Update除了有基本的语法格式外还有其它的一些常用的格式:

(1)、更新数据为内部变量或者函数,格式为:

    update 表名

    set 字段名1=函数1[…,字段名n=函数n]

    [where 条件]

    eg:

update student

       set sbirth=getdata()

       where sno=’990001’

(2)、更新数据为同一记录的其他字段值(将一张表中的同一记录的某个字段值改成另一字段的值),格式为:

    update 表名

    set 字段名1=字段名m[…,字段名m=字段名n]

    from 表名1,表名2

    [where 条件]

eg:  

           update student

set sdept=stu.sname

from student,student as stu

where student.sno='990001'

(3)、更新数据为不同表的字段值,该方式要求更新数据的目标表和源表有相同的字段(将一个表中字段的值赋给另一个表的某个字段),格式为:

    update 表名1

set 表名1.字段名1=表名2.字段名1[...,表名1.字段名n=表名2.字段名n]

from 表名1,表名2

[where 条件]

eg:

      update student

set sdept=stu.sdept

from student,stu

where student.sno='990001' and stu.sno='990002'

(4)、更新数据为同一个表中的某些字段值(将一个表中不同记录之间的字段值进行替换),格式为:

    update 表名1

set 表名1.字段名1=表别名.字段名1[...表名1.字段名n=表别名.字段名n]

from 表名1,表名 as 别名

[where 条件]

eg:

           update student

set sdept=stu.sdept

from student,student as stu

where student.sno='990001' and stu.sno='990002'

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值