zoukankan      html  css  js  c++  java
  • 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条件];

  • 相关阅读:
    windows安装MongoDB进度条卡住,window安装mongo系统错误 2,系统错误5的解决办法(转载)
    大前端涉猎之前后端交互总结3:使用PHP进行表单数据删除与查询
    异常处理
    java 触发鼠标点击事件 向linux发送指令
    反射机制
    静态方法,类方法,属性方法
    python 类
    python 正则表达式
    python 加密模块
    python xml 与配置文件处理
  • 原文地址:https://www.cnblogs.com/langgj/p/10320485.html
Copyright © 2011-2022 走看看