zoukankan      html  css  js  c++  java
  • oracle2约束添加&表复制&拼接

    alter table student3 add constraint uq_name unique(name)
    -- 添加主键,约束名可省
    alter table student3 add constraint pk_id primary key(id) -- constraint pk_id 可省略

    create table Class(
    id number(4) constraint pk_id primary key, -- 列级约束,
    name varchar2(20),
    sex varchar2(2)
    );
    alter table Class add constraint uq_nam unique(name);
    alter table Class modify sex default '男' not null; -- default '男' 及 not null只能用modify添加,(修改),且default在not null前

    create table student2(
    id number(4),
    constraint pk_id2 primary key(id), -- 表级约束
    name varchar2(20) not null,
    cid number constraint pk_cid references Class(id) -- 列级约束(外键) not null只能用列级约束
    );

    alter table student2 drop constraint pk_cid; -- 修改表丢掉约束drop constraint 约束名
    alter table student2 drop primary key; -- 丢掉主键可以直接drop primary key,不用写主键名,一个表只有一个主键

    create table student4 as select * from student3 where 1=2 -- 复制表结构
    create table student4 as select * from student3 -- 复制表结构同时复制全部数据
    insert into student4 select * from student3 where id=1 -- 复制部分数据

    select * from student3 where birthday is null -- 查询为空用的是 字段名 is null 而不是 =null
    select * from student3 where birthday is not null -- 查询不为空用的是 字段名 is not null

    -- 拼接, ||相当于java里的拼接符+
    select '编号'||id,name from student3
    select '编号'||id,name||'姓名' from student3
    select '编号'||id||name||'姓名' from student3

    -- 日期与数值运算的是天数

    日期 – 数字 = 日期
    日期 + 数字 = 日期
    日期 – 日期 = 数字


    -- 四种约束类型:
    -- 实体完整性(主键约束),域完整性(限制数据类型,检查链接,唯一约束,非空约束),
    -- 引用完整性(外键链接),自定义完整性(规则,储存过程,触发器)

  • 相关阅读:
    Linux的概念与体系
    Python快速教程
    Qt控件精讲一:按钮
    xml2-config not found
    Ubuntu 12.04更新源
    Adaboost的几个人脸检测网站
    关于matlab矩阵卷积conv2和傅里叶变换求卷积ifft2的关系
    char数组和String互转
    STL中vector的赋值,遍历,查找,删除,自定义排序——sort,push_back,find,erase
    《离散数学》-图论6.7
  • 原文地址:https://www.cnblogs.com/21556guo/p/13530777.html
Copyright © 2011-2022 走看看