Oracle数据库日常SQL的使用

DDL 语句(数据定义语言Create、Alter、 Drop、Truncate)

1、建表:create table 表名();

2、复制表结构及其数据:create table 新表名 as select * from 旧表名

3、只复制表结构:create table 新表名 as select * from 旧表名 where 1=2;

注意:2 3 只是复制了表结构但是没有复制索引还有主键等

  4、添加、修改、删除表结构 :alter table 表名 add/modify/drop;

   添加/修改 alter table add/modify();
  删除单列 alter table 表名 drop column 列名;
  删除多列 alter table 表名 drop(列名1,列名2,....);

  5、重命名表 :alter table 表名 rename to 新表名;

  6、重命名列:alter table 表名 rename column 列名 to 新列名;

  7、添加主键约束:alter table 表名 add constraint 主键约束名 primary key(列名);

  8、删除主键约束:alter table 表名 drop constraint 主键约束名;

  9、删除表:drop table 表名;

  10、清空表:truncate table 表名;

DML 语句(数据操作语言Insert、Update、 Delete、Merge)

  1、插入语句:insert into 表名 values();

  2、更新语句:update 表名 set 字段名 = 值  [where条件];

  3、删除语句:delete from 表名 [where条件];

  4、更新或插入:

merge into 目标表
using 源表
on(目标表.列 = 源表.列)
when matched then update set 目标表.跟新列 = 源表.跟新列
when not matched then insert(目标表字段) values(源表字段)

  5、只复制表数据
    表结构一致:insert into 新表名 select * from 旧表名 [where条件];
    表结构不一致:insert into 新表名(c1,c2) select c1,c2 from 旧表名 [where条件];

 

posted @ 2019-01-25 16:51  calmLang  阅读(300)  评论(0编辑  收藏  举报