zoukankan      html  css  js  c++  java
  • Oracle中建表和指定表空间

    --建一个表
    create table HH2(

    tid number primary key ,--主键设定

    tname varchar2(20)

    );

    --删除表
    drop table HH;

    --表空间(相当于一个数据库)(DBA权限)
    create tablespace test
    datafile 'D:test.dbf'
    size 10M
    autoextend on
    next 10M
    maxsize 100M

    --指定表在那个表空间里面(默认在USERS表空间里)
    create table HH(tid number primary key)
    tablespace test;
    select * from tabs;

    --删除 表空间
    drop tablespace test including contents and datafiles --连带物理文件和表空间中的数据也一起删除

    --建表建约束
    create table student1(
    sid number primary key ,
    sname varchar2(20) not null,
    sage number,
    ssex char(2),
    saddress varchar2(100),
    cid number references tclass(cid)--建立外键关系
    );

    create table tclass
    (
    cid number primary key,
    cname varchar2(20)
    );
    --唯一unique 检查 check 默认值 modify 添加外键关系 添加列
    alter table student1 add constraint UQ_student1_sname unique(sname);
    alter table student1 add constraint CK_student1_agae check(sage between 19 and 70);
    alter table student1 modify ssex default '男';
    alter table student1 add constraint FK_student1_cid foreign key(cid) references tclass(cid);
    alter table student1 add dt date;
    --删除约束
    alter table student1 drop constraint UQ_student1_sname ;

  • 相关阅读:
    SQL-server 学习笔记(三):实战建库建表,插入数据
    SQL-server 学习笔记(二):约束
    SQL-server 学习笔记(一):数据库创建
    操作系统——第五章
    操作系统——第四章
    操作系统——第三章
    操作系统——第二章 (二)
    Python之路,Day7
    Day6
    Day5
  • 原文地址:https://www.cnblogs.com/laotan/p/3663053.html
Copyright © 2011-2022 走看看