这里主要记录一下Oracle中关于表的创建和维护的操作。
一、表名规范:
1.字母开头
2.长度不超30字符
3、不能使用保留字
二、数据类型:
在学习Oracle之前,有必要了解一下Oracle和sql中不同的数据类型。Oracle中没有sql那么多的类型。
1、char 定长 最大2000字符,查询比较快,适用于经常要查询的语句
2、varchar2 变长 最大4000字符,节省空间
3、clob(character large objiect) 字符型大对象,最大4G
4、数字类型:
number 10的-38到正的38次方可以表示整数也可以表示小数。
number(5,2):一个小数有五位有效数字,2为小数 -999.99---999.99
number(5):一个五位整数 -99999---99999
5、日期类型:
date 包含年月日时分秒
timestamp 时间戳
6、图片类型:
可以存储二进制数据、图片/声音、视频(放到数据库中比较安全,普通的话放到一个文件夹中)
三、表管理的常用命令:
1、查看表结构:
desc scott.emp;
2、建表:
create table student
(
xh number(4), --学号
xm varchar2(20), --姓名
sex char(2), --性别
birthday date, --出生日期
sal number(7,2) --奖学金
)
create table classess
(
classId number(2),
cname varchar2(40)
)
3、添加字段:
alter table student add
(classId number(2))
4、修改字段类型或者名字:(不能有数据)
alter table student modify
(xm char (30))
5、删除字段:
alter table student drop column sal;不能删除sys的列??
5、修改表名:
rename student to stu
7、删除表:
drop table student
8、添加数据:
insert into student values
(
1,'小明','男','11-12月-1997',124.5,12
)
9、修改默认的日期格式;
alter session set nls_date_format ='yyyy-mm-dd'
10、创建序列
create sequence seq_a minvalue 1000 maxvalue 99999999 start with 1000 increment by 1 nocache;
11、查询序列
select seq_a.nextval from dual;