oracle表的创建

--创建表空间
create tablespace jt16
datafile 'C:\oracle\oradata\orcl\jt16.dbf'
size 100M
autoextend on;

--创建用户
create user yl identified by accp
default tablespace jt16;

--给用户授权
grant connect,resource to yl;
--收回权限
revoke connect from yl;

--创建表
/*create table 表名(
列名  列的数据类型 列的特征
)*/

create table student(
stuid number(4) not null,
stuname varchar2(50) not null,
stusex char(2) not null,
stuage number(3) not null,
stuaddress nvarchar2(100),
stuqq number(11),
stuemail varchar2(100)
);

--创建课程表
create table course(
cid number(1) primary key,
cname varchar2(50) not null
);


--添加一列
--修改表的结构用 alter table 表名 add()
alter table student add(stuphone varchar2(13));
--修改列
alter table student modify(stusex varchar2(4) default '男');
--删除列
alter table student drop column stuphone;
--删除多列
alter table student drop (stuemail,stuqq);
--给学生表添加一个课程列
alter table student add(cid number(1));

--删除表的语法
drop table student;

--为表添加约束
--为学生编号列添加主键约束
alter table student add constraint pk_stuid primary key(stuid);
--给性别加一个检查约束
alter table student add constraint ck_stusex check(stusex='男' or stusex='女');
--给QQ号加一个唯一约束
alter table student add constraint uq_stuqq unique(stuqq);
--给学生的课程列加一个外键
alter table student add constraint fk_cid foreign key(cid) references course(cid);
--删除约束
alter table student drop constraint fk_cid;

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值