1.创建表stu
create table stu(
sid number,
sname varchar2(2),
ssex
varchar2(2)
);
2.显示表describe stu
desc stu;
3.把sid设为主键
alter table stu modify sid primary key;
4.修改sname的属性
alter table stu modify sname varchar2(5);
5.删除主键
alter table stu drop primary key;
6.增加主键并增加主键的名称
alter table stu add constraint pk_sid primary key
(sid);
7.删除主键,如果有名称则用名称删除,如果没有,可以直接删除
alter table stu drop constraint pk_sid;
alter table stu drop primary
key;
8.增加列,此处不加column,否则会报错
alter table stu add age number;
9.修改sage属性的两种方法
alter table stu modify sage check (sage>10 and
sage<50);
alter table stu modify sage check (sage between 10 and 50);
10.删除列sage,此处必须加column
alter table stu drop column sage;
11.修改ssex的属性
alter table stu add ssex varchar2(2) check(ssex='男'or
ssex='女');
alter table stu add ssex varchar2(2) check (ssex in('男','女'));
alter table stu modify ssex varchar2(2) check (ssex in(0,1));
12.创建序列,注意cache的值,防止出现如下错误:CACHE 值必须小于 CYCLE 值
create sequence
seq_sid
start with 1
increment by 2
maxvalue 10
minvalue 1
cache
5
cycle;
13.修改序列,此处不加modify
alter sequence seq_sid
increment by 3
maxvalue
30
minvalue 0
cache 10
cycle
order;
14.删除序列
drop sequence seq_sid;
15.插入表中数据
insert into stu (sid,sname,ssex,sage)values
(seq_sid.nextval,'one','男',19);
16.删除表中的所有数据,此处必须加table
truncate table stu;
17.插入数据如下,显示违反检查约束条件的原因:汉字在oracle中占的字节为三个。
insert into stu
(sid,sname,ssex,sage)values (seq_sid.nextval,'on','男',19);
18.关闭主键限制,方便插入数据
alter table stu disable constraint pk_sid;
alter table
stu disable primary key;
19.打开主键限制
alter table stu enable constraint pk_sid;
alter table stu
enable constraint primary key;
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/26789504/viewspace-718565/ ,如需转载,请注明出处,否则将追究法律责任。