Posted on 2006-11-10 20:16
黑夜ちつ独行者 阅读(340)
评论(0) 编辑 收藏
3.1、创建表
格式:create table 表名;
3.2、删除表
格式:drop table 表名;
3.3、创建临时表
格式:create gkoabl temporary table temp
AS
select Name,PhoneNo from friend;
3.4、复制表
格式:create table My_friend AS select*from friend;
3.5 、创建非空约束 ( not null )
3.6、指定默认值 ( default '默认值内容' )
3.7、设定主键 ( primary key )
3.8、设置唯一约束 ( 语句后面加 unipue )
3.9、设置检查约束
格式:age int check(age between 20 and 50);
或 sex varchar check(sex in ('男','女'));
3.10 、使用序列 ( sequences)
格式:
create sequences friendidseq;
(序列的初始值为1,增量为1)
create sequences friendidseq increment by 1
start with 1000;
(序列的初始值为1000,增量为1)
显示最后一个序列值
select friendidseq.currval from dual;
3.11、使用自动编号字段
格式:create sequences seq;
create or replace trigger autonumber
before insert on friend
for each row
begin
select seq.nextval
into :new.friendid from dual;
end;
3.12、外键约束
关键字:constraint foreign key()
references
举例
create table student(
studentid int not null primary key,
name varchar(20) not null
);
create table phone(
phoneid int not null primary key,
studentid int not null,
phone varchar(14),
constraint fid_fk foreign key(srudentid)
references student(studentid)
) ;
3.13、创建索引
格式:create index nameindex on student (name); (创建非唯一索引)
create unique index nameindex on student(name); (创建唯一索引)
查询索引:
select student.name from student where name = '但是';
select student.name from student where name = '%电' ;
删除索引
drop index nameindex;