Oracle:创建表

1、创建表:
     例:创建用户表users(id整型、name字符串、birthday日期、sal整型,默认今天)
           create table users(
                                       id number(5) primary key,
                                       name varcher2(8) not null unique,
                                       sal number(6,2) not null,
                                       birthday date default sysdate
                                       );
      说明:其中primary key表示主键,not null表示不为空,unique表示唯一,default sysdate表示默认今天。
2、进入回收站,即删除表:
     格式:drop table 表名
     例:删除users表 drop table users;
3、查询回收站中的对象:
      show recyclebin;
4、闪回,即:将回收站还原:
     格式1:flashback table 表名 to before drop;
     格式2:flashback table 表名 to before drop rename 新表名;
     注意:若回收站中,有相同的表名的多个表,执行闪回会还原最近的那个。
5、彻底删除表:
     格式:drop table 表名 purge;
6、清空回收站:
     purge recyclebin;
7、check()约束:
     例:创建表students,包括id、name,gender字段,其中性别只能是男或女。
           create table students(
                                             id number(3) primary key,
                                             name varchar2(4) not null unique,
                                             gender varchar2(2) not null check(gender in('男','女')));
8、foreign key约束外键:
     例:create table orders(
                                          cid number(3),
                                          constraint cid_FK foreign key(cid) reference customer(cid));
    说明:reference customer(cid)表示引用customer表的cid字段。
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值