oracle 更新数据语句,数据更新语句update
发布日期:2021-06-24 12:44:15 浏览次数:2 分类:技术文章

本文共 3362 字,大约阅读时间需要 11 分钟。

SQL的update语句怎么写

UPDATE 表名称 SET 列名称 = 新值 WHERE 列名称 = 某值,update语句的写法:

1、UPDATE table_name

2、SET column1=value1,column2=value2,。

3、WHERE column(1)=value(1),column(2)=value(2)。and column(n)=value(n);

4、UPDATE Person SET Address = 'Zhongshan 23', City = 'Nanjing',WHERE LastName = 'Wilson'

扩展资料

SQL的update语句写法的特点

1、一体化:SQL集数据定义DDL、数据操纵DML和数据控制DCL于一体,可以完成数据库中的全部工作。

2、使用方式灵活:它具有两种使用方式,即可以直接以命令方式交互使用;也可以嵌入使用,嵌入到C、C++、FORTRAN、COBOL、JAVA等主语言中使用。

3、非过程化:只提操作要求,不必描述操作步骤,也不需要导航。使用时只需要告诉计算机“做什么”,而不需要告诉它“怎么做”。

4、语言简洁,语法简单,好学好用:在ANSI标准中,只包含了94个英文单词,核心功能只用6个动词,语法接近英语口语。

参考资料来源:搜狗百科—update (数据库SQL语法用语)

数据库更新语句怎么写

如果按你的要求需要写个存储过程来实现。麻烦。

如果按下面来做的话,会有重复值,

update 表名 set column_no=datepart(day,column_time)

建议你把column_no 按如20090101来更新较方便,这样能与column_time能对应上。

update 表名 set column_no=(datepart(year,column_time)*100+datepart(month,column_time))*100+datepart(day,column_time)

SQL数据批量更新语句怎么写

--试试下面个吧,如果使用存储过程可能会好些

create table a1(

id1 int primary key,

va1 varchar(20)

)

drop table b2

create table b2(

id2 int primary key,

va2 varchar(20)

)

--创建一张中间表来储存被删除的id

create table idrecord

(

id int

)

--a1 插入 测试数据

insert into a1 values (1, '地理');

insert into a1 values (2,'物理');

--b2 插入 测试数据

insert into b2 values (1, '数学');

insert into b2 values (3,'英语');

select * from a1

select * from b2

--如果A1存在ID与B1相同的数据,则更新,由于主键不能重复插入,所以先删除数据再进行添加,

--记录被删除的id

delete from idrecord

insert into idrecord select id1 from a1 where id1 in (select id2 from b2)

--先删除 在 a1 ID 与 b2相同的数据

delete from a1 where id1 in (select id2 from b2)

insert into a1 select * from b2 where id2 in (select * from idrecord)

--如果A1不存在ID与B1相同的数据,则添加B1中的数据到A1中

insert into A1 select * from b2 where id2 not in (select id1 from a1)

oracle数据库update语句

update两表关联的写法包括字查询

1.update t2 set parentid=(select ownerid from t1 where t1.id=t2.id);

2. update tb_client_win_lost_report a set a.rolling_code_id=2

where game_code_id=70000

and exists

(select 'x' from (select a.id

from (select id,level_ from tb_admin_role connect by prior id=parent_id start with id =1) a,

(select lv_id from tb_rolling_plan where rolling_code_id = 2 and game_code_id=70000) b

where b.lv_id=a.id) c where a.role_id=c.id)

and rolling_code_id=1

3. update (select rolling_code_id from tb_client_win_lost_report a,temp_role_id b

where a.role_id=b.id

and rolling_code_id=1) a set a.rolling_code_id=2;

4. update tb_client_win_lost_report a set a.rolling_code_id=2

where game_code_id=70000

and exists

(select 'x' from (select id from temp_role_id) c where a.role_id=c.id)

and rolling_code_id=1

and rownumcommit;

5.update 多个字段的写法

update a set (c1,c2,c3) =(select b1,b2,b3 from b where。。) where 。。;

sql update 语句

按你这个脚本直接改:

create trigger update_student on student

for update

as

begin

declare @班级 int

select @班级=班级 from inserted

update class set 人数 = 人数 + @@rowcount

where 班级=@班级

select @班级=班级 from deleted

update class set 人数 = 人数 - @@rowcount

where 班级=@班级

end

inserted是刚刚增加的整行,deleted是刚刚删除的整行数据

没有updated,update的过程就是先delete,再insert,所以用inserted和deleted能表达update的过程了

另外你这个触发器只能对更新结果是1个班级的有效,如果是多个班级,在select @班级=班级 from inserted这句上会报错

最好的办法还是

create trigger update_student on student

for update

as

begin

update class set 人数 = 人数 + 人数_add

from (select 班级,count(1) as 人数_add from inserted group by 班级) b

where class.班级=b.班级

update class set 人数 = 人数 - 人数_min

from (select 班级,count(1) as 人数_min from deleted group by 班级) b

where class.班级=b.班级

end

转载请注明出处华阅文章网 » 数据更新语句update

转载地址:https://blog.csdn.net/weixin_32820131/article/details/116384447 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:linux怎么用命令设置日期,Linux系统教程_怎样用命令行更改Linux系统的日期和时间?...
下一篇:oracle数据库对象类型转换,Oracle数据库数据对象分析(转)

发表评论

最新留言

哈哈,博客排版真的漂亮呢~
[***.90.31.176]2024年04月01日 09时21分19秒