Oracle 知识备份(二)2011年4月4号

来源:互联网 发布:mac popo登录408 编辑:程序博客网 时间:2024/06/06 13:52

--建表语句

主键约束、非空约束、唯一约束、检查约束、主-外键约束
drop table person;
drop table book;
create table person
(
    pid       varchar2(20),
    name      varchar2(50)    not null,
    age       number(3)       not null,
    birthday  DATE,
    sex       varchar2(2)     default '男',
    constraint person_pid_pk primary key(pid),
    constraint person_age_ck check(age between 0 and 150),
    constraint person_sex_ck check(sex in ('男','女','中')),
    constraint person_name_uk unique(name)
)

create table book(
      bid         number     primary key not null,
      bname       varchar2(30),
      bprice      number(5,2),
      pid         varchar2(20),
      constraint person_book_pid_fk foreign key(pid) references person(pid) on delete cascade
);

 

create table sporter(
       sporterid        number,
       name             varchar2(20) not null,
       sex              varchar2(2)  ,
       department       number not null,
       constraint sporter_sportid_pk primary key(sporterid)
);

create table item(
       itemid           number,
       itemname         varchar2(200),
       location         varchar2(200),
       constraint item_itemid_pk primary key(itemid)
);

create table grade(
       sporterid        number,
       itemid           number,
       mark             number,
       constraint grade_mark_ck check(mark in (6,4,2,0)),
       constraint grade_sporterid_fk foreign key(sporterid) references sporter(sporterid) on delete cascade,
       constraint grade_itemid_fk foreign key(itemid) references item(itemid) on delete cascade
);


drop table person cascade constraint;
alter table 表名称 add constraint 约束名称 约束类型

 

create table myemp as select * from emp;保存表结构即数据

update 表名称 set 字段=新值,字段=新值
where 修改条件;

delete from 表名称 where 删除条件;

删除表结构及表中的数据
DROP TABLE table_name

DROP TABLE "SYSTEM"."APP_CORP_ACHIEVEMENTS" CASCADE CONSTRAINTS

 

表中增加字段
alter table <table_name> add <column_name> <data_type>

1、添加字段
alter table table_name add column1 type add column2 type add column3 type ... ;
 
2、删除字段
alter table table_name drop column column_name;
 
3、修改字段类型
alter table table_name modify (column_name type);

4、修改字段名
alter table table_name rename column old_value to new_value;

5。为表重新命名
rename 就表名称 to 新表名称

6.截断表
truncate table 表名称

 

建临时表

create global temporary table app_corp_temp_strudsgn(name varchar2(50),
                                                     id_no varchar2(30),
                                                     speciality varchar2(60),
                                                     corp_name varchar2(150),
                                                     lic_no varchar2(50),
                                                     lic_seal_no varchar2(50),
                                                     time varchar2(30))
                                                     on commit preserve rows;

 

 

集合操作:

并(union)
交(intersect)
差(minus)

创建视图:create view 视图名称 as 子查询;create or replace 视图名称 as 子查询 with check option/with read only;
删除视图:drop view 视图名称;

序列:

create sequence myseq;
drop sequence myseq;

nextVal,currVal.
--increment by n  增长幅度
--start with n 起始位置

create synonym 同义词名称 for 用户名.表名称

 

导出单表
imp inseprion/111111@local_szjsj file=d:/clob_test.dmp tables=clob_test log=implog.txt
导入单表
imp inseprion/111111@local_szjsj file=d:/clob_test.dmp tables=clob_test ignore=y log=d:/implog.txt

导入整个库:
imp inseprion/111111@local_szjsj file=D:/Data_backup/web20050126.dmp full=y;

imp test/test@WSSB_NW file=D:/Data_backup/conmis20030119.dmp full=y;

 

原创粉丝点击