Oracle基本语句(二)

2014-11-24 09:12:03 · 作者: · 浏览: 1
cott log=d:\empimp.log
导入自己的表 imp userid=scott/orcl@orcl tables=emp file=d:\emp.dmp
导入表到其它用户 imp userid=system/orcl@orcl tables=emp file=d:\emp.dmp fromuser=system touser=scott log=d:\empimp.log
导入表的结构 imp userid=scott/orcl@orcl tables=emp file=d:\emp.dmp rows=n log=d:\empimp.log
导入数据 如果对象(如比表)已经存在可以只导入表的数据
imp userid=scott/orcl@orcl tables=emp file=d:\emp.dmp ignore=y log=d:\empimp.log
注意formuser是表本来属于哪个用户 touser现在传递给哪个用户
9 表空间 www.2cto.com
创建表空间 create tablespace zhu datafile 'C:\oracle\product\10.2.0\oradata\zhu.dbf'
size 50m autoextend on next 50m maxsize unlimited extent management local;
create user zhu identified by zhu default tablespace zhu;
create table student(SNo number(4),Name nvarchar2(50),Sex char(2),Birthday date,Salary number(7,2) default 1000 not null) tablespace zhu;
知道表空间名,显示该表空间包括的所有表
select * from all_tables where tablespace_name='zhu';
知道表名,查看该表属于那个表空间
select tablespace_name, table_name from user_tables where table_name='emp';
删除表空间 drop tablespace zhu including contents and datafiles cascade constraints;
10 约束
not null unique primary key foreign key check
alter table class add constraint class_key primary key (classid);
11 主键
自动增长
先创建一个表
create table student(SNo number(4) primary key,Name nvarchar2(50),Sex char(2),Birthday date,Salary number(7,2) default 1000 not null)
自定义一个sequence
create sequence student_sequence increment by 1 start with 1 nomaxvalue nocycle nocache; www.2cto.com
创建一个触发器
create trigger student_trigger before insert on student for each row when(new.SNo is null) begin select student_sequence.nextval into:new.SNo from dual;end;/
最近插入一行数据
insert into student(Name,Sex,Birthday,Salary) values('朱文锋','男','01-5月-12',2000);
GUID
先创建一个表
create table student2(SNo char(32) primary key,Name nvarchar2(50),Sex char(2),Birthday date,Salary number(7,2) default 1000 not null)
然后插入一行数据
insert into student2(SNo,Name,Sex,Birthday,Salary) values(sys_guid(),'朱文锋','男','01-5月-12',2000);
在sql server中是newid()函数
作者 朱文锋