transaction :rollback :回滚 commit :提交
1、当进行了有系列的sql语句,但是使用rollback 就会取消所有操作。如果commit了,就不能再回滚了
2、当进行了一些列的sql语句,但是使用了如create ,dorp 等操作,自动提交
3、断电了,会自动回滚
varchar2(10)变长字符串,最大可以存储4k.
char():定长字符串,存储效率比较高,但是浪费内存
number(8,3):整个数字一共八位,小数点三位b
date():年月日,时分秒
long:变长字符串,最大字符串可以达到2个G
1、创建学生表:
create table stu{
id number(6) unique not null constraint pk_id primary key ,
name varchar2(20),
sex number(1),
age number(3) constraint stu_age not null,
sdate date,
grade number(2) default 1,
class number(4) references class(id), //创建外键约束,等价于下面的语句创建外键
email varchar2(50) unique
//constraint stu_id_pk primary key(id,name)//将id和name组合作为组件
//constraint stu_class foriegn key(class) references class(id) //创建外键约束
};
2、创建班级表
create table class{
int number(4) primary key,
name varchar2(20) nont null
}
insert into stu vaules(1,'zhaoyehong',1,23,1990-10-10,1,2,‘542983647@qq.com’);
insert into stu(id,name)value(1,'xuximing');
not null:非空约束
constraint stu_age not null :给约束命名
unique:不能重复,唯一约束
constraint name_email unique(name,email) :name 和email的组合不能重复
primary key:可以通过这个可以表示整条记录。既不能为空又不能重复
foreign key :外键,被参考的字段必须是其他表的主键
3、修改表结构
alert table stu add(addr varchar2(100));
alert table stu drop (addr);
alert table stu modify(addr varchar2(50));
alert table stu drop constraint stu_age ;-->删除约束条件
alert table stu add constraint stu_id foreign key class reference class(id);-->添加
drop table tablename;-->删除表
索引:读取数据效率比较高,插入效率比较低【不仅要插入表中,还要修改索引表】。
需要访问量大的时候就可以建立索引
1、create index idx_stu_email on stu (email); -->创建索引
2、drop index idx_stu_email;
3、select index_name from user_indexes -->查找索引
视图
1、create view v$
2、select view_name from user_views -->查看试图
序列 :参数一系列的数,不重复
1、create table article{
id number,
title varchar(1024),
cont long
}
2、create sequence seq
3、select seq.nextval from dual -->输出1
4、select seq.nextval from dual -->输出2
5、select seq.nextval from dual -->输出3
6、insert int article values(seq.nextnal,'a','b'); -->自动发产生编号
7、drop sequence -->删除序列