zoukankan      html  css  js  c++  java
  • oracle表的基本操作

    创建表:

    Create table username.table_name(/*username 可以没有*/

    Sid number(2) primary key,      /*定义主键 可以没有*/

    Nane varchar2(20) not null,

    Age number(3),

    Constraint sid primary key(sid)  /*或者添加约束,定义主键*/

    ) tablespace tablespace_name; /*表空间可以不指定*/

    修改表:

    添加列:

             Alter table table_name add column column_name column_type(n);

             A;ter table table_name add (column_name column_type(n),column_name column_type(n));

    删除列:

             Alter table table_name drop column column_name;

             Alter table table_name drop (column_name,column_name);

    更改列属性:

             Alter table table_name modify column_name new_column_type(n);

    更改表名:

             Alter table table_name rename to new_table_name;

    修改表所在的表空间:

             Alter table table_name move new_tablespace;

    删除表:

             Drop table table_name;

    表约束:

    创建表时:

             Create table table_name(

                       Sid number(3) primary key,

                       cid number(3) unique,

                       aid number(3) not null,

                       fid number(3) references table_name(priamry key));

    Not null:

     Alter table table_name modify aid null;

              Alter table table_name modify aid not null;

    Unique:

             Alter table table_name add unique(cid);

             Alter table table_name drop unique(cid);

             Alter table table_name add constraint constraint_name unique(cid);

             Alter table talbe_name drop constraint constraint_name

    Primary key:

             Alter table table_name add constraint constraint_name primary key(sid,cid);

             Alter table talbe_name drop constraint constraint_name;

    Foreign key:

             Alter table talbe_name add constraint constraint_name foreign key(cid) references table_name(primary key)

             Alter table table_name drop constraint constraint_name;

    Check:

             Alter table table_name add constraint constraint_name check(aid>3);

             Alter tabel table_name drop constraint constraint_name;

    Constraint:

             Alter table table_name disable constraint constraint_name;

             Alter table table_name enable constraint constraint_name;

             Alter table table_name modify constraint constraint_name enable;

             Alter table talbe_name modify constraint constraint_name disable;

  • 相关阅读:
    类和接口对比
    concurrenthasmap
    java中的三大注解
    基本数据类型,注意首字母
    常见ascii码记忆
    Java软件工程师面试题:Java运行时异常与一般异常有什么不一样?
    &和&&的共同点和区别、Java字符含义和Java创建对象的几种方式
    Java面试题中常考的容易混淆的知识点区别
    Java面试题整理:这些Java程序员面试中经常遇见的题目,必须掌握才能有好结果
    Spring Cloud 微服务架构的五脏六腑,统统晒一晒!
  • 原文地址:https://www.cnblogs.com/kaibing/p/7861521.html
Copyright © 2011-2022 走看看