oracle与Mysql的增删改语法区别对⽐
1. 创建表
MySQL:
create table test
(id int(10) not null primary key comment '主键id',
amt decimal(18,2) default null comment '⾦额'
)comment='测试表';
Oracle:
create table t1(
id varchar2(32) defaule 0 not null primary key,
name varchar2(32) ,
age varchar2(32)
)
添加表注释:
comment on table t1 is '个⼈信息';
添加字段注释:
comment on column t1.id is 'id';
comment on column t1.name is '姓名';
comment on column t1.age is '年龄';
2. 删除表
MySQL:drop table if exists tableName;
Oracle:drop table tableName;
注:Oracle没有if exists关键字,也没⽤类似if exists的SQL语法。
drop、truncate、delete的区别:
1、drop (删除表):删除内容和定义,释放空间。简单来说就是把整个表去掉.以后要新增数据是不可能的,除⾮新增⼀个表。
drop语句将删除表的结构被依赖的约束(constrain),触发器(trigger)索引(index);依赖于该表的存储过程/函数将被保留,但其状态会变为:invalid。
2、truncate (清空表中的数据):删除内容、释放空间但不删除定义(保留表的数据结构)。与drop不同的是,只是清空表数据⽽已。
注意:truncate 不能删除⾏数据,要删就要把表清空。
3、delete (删除表中的数据):delete 语句⽤于删除表中的⾏。delete语句执⾏删除的过程是每次从表中删除⼀⾏,并且同时将该⾏的
删除操作作为事务记录在⽇志中保存
以便进⾏进⾏回滚操作。
truncate与不带where的delete :只删除数据,⽽不删除表的结构(定义)
3. 修改表名
MySQL:
B.alter table oldtableName rename to newtableName;
Oracle:
alter table oldtableName rename to newtableName;
4. 修改表注释
MySQL:alter table oldtableName comment '新注释'
Oracle:comment on table 表名 is '表的注释信息';
5. 添加字段
MySQL:
A. alter table tableName add [column] columnName1 int(10);
B. alter table tableName add [column] columnName1 int(10), add column columnName2 int(10);
Oracle:
A.alter table tableName add columnName1 int;
B.alter table tableName add (columnName1 int);
C.alter table tableName add (columnName1 int, columnName2 int);
注:对于添加多列时需要使⽤C,不能像MySQL那样重复使⽤add column关键字。
在指定位置插⼊新字段:
MySQL:
A.alter table tableName add [column] columnName 数据类型 comment '注释' after 指定某字段;
B.alter table tableName add [column] columnName 数据类型 comment '注释' first
没有before的⽤法,只有first
Oracle:⽆这样的⽤法,只能插在最后。
6. 删除字段
删除⼀个字段
alter table tableName drop column columnName;
删除多个字段
alter table tableName drop (columnName1,columnName2);
7. 修改字段名
MySQL:alter table tableName change [column] oldcolumnName newcolumnName 新数据类型(必须);
Oracle:alter table tableName rename column oldcolumnName to newcolumnName; 注:不能有字段类型
8. 修改字段的注释
MySQL:alter table tableName modify column columnName 数据类型 comment '修改后的字段注释';
Oracle:comment on column 表名.字段名 is '字段的注释信息';
9. 修改字段类型
MySQL:alter table tableName modify [column] columnName 新数据类型新默认值新注释;
Oracle:不允许修改字段类型
10. 插⼊数据
MySQL:
insert into tableName (column1,column2,column3) values (null,column2value,column3value)
Oracle:
truncate的区别
insert into tableName (column1,column2,column3) values (tableName.NEXTVAL,column2value,colum
n3value)注:column1是⾃增主键字段,默认Oracle已创建了tableName名的序列

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。