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

  • 相关阅读:
    windows server2008自动登录
    WindosServer2008 激活问题。
    [转]10分钟写出你的第一个包含CRUD的Rails程序
    SQL 2008操作相关
    没有域环境安装SharePoint2010
    D3D10彻底抛弃了固定图形管线
    MultiUser01 – 简介
    6种Socket I/O 模型性能比较,图
    Dr程序耗尽了CPU
    IDXGIOutput接口
  • 原文地址:https://www.cnblogs.com/renpei/p/5457753.html
Copyright © 2011-2022 走看看