• Oracle脚本笔记


    //创建一个表
    create table  表名
    (字段名1 varchar2(20) not null);
    //多个用 , 隔开
    //添加字段
    alter table 表名
    add (字段名2 varchar2(30) default ‘初始值' not null);
     COMMENT ON COLUMN 表名.字段名 IS '注释';

    //修改一个字段
    alter table 表名
    modify (旧字段名 varchar2(16) default ‘新字段名');

    alter table 表名 rename column 旧字段 to 新字段;

    //删除一个字段
    alter table 表名  drop column 字段名;

    //修改列的名称
    ALTER TABLE 表明 RENAME COLUMN 旧名 to 新名;

    //重命名表
    ALTER TABLE 旧表名 RENAME TO 新表名;

    //向表中添加主键约束
    alter table 表名 add constraint pk_表名 primary key(主键);
    //======================================

    1、创建表的同时创建主键约束
    (1)无命名
    复制代码 代码如下:

    create table student (
    studentid int primary key not null,
    studentname varchar(8),
    age int);

    (2)有命名
    复制代码 代码如下:

    create table students (
    studentid int ,
    studentname varchar(8),
    age int,
    constraint yy primary key(studentid));

    2、删除表中已有的主键约束
    (1)无命名
    可用 SELECT * from user_cons_columns;
    查找表中主键名称得student表中的主键名为SYS_C002715
    alter table student drop constraint SYS_C002715;
    (2)有命名
    alter table students drop constraint yy;

  • 相关阅读:
    Catalan数
    完全背包
    日期问题
    01背包
    NOJ2076
    858. Prim算法求最小生成树
    839. 模拟堆
    850. Dijkstra求最短路 II
    849. Dijkstra求最短路 I
    859. Kruskal算法求最小生成树
  • 原文地址:https://www.cnblogs.com/renpei/p/5457753.html
Copyright © 2020-2023  润新知