步骤一:创建一个新的用户,并授权。参考语法
步骤二:创建一个新的表空间,并指定为新用户的默认表空间
步骤三:按照表的设计要求,创建表。只给出一个示例,其它表请自己尝试创建
步骤四:为创建的表填入适当数据,体会约束的作用。
步骤五:为雇员表的empid创建索引
步骤六:在数据字典中查看新创建的表和约束
- create user appadmin
- identified by appadmin
- /
- grant create session,dba
- to appadmin
- /
- select * from all_users
- /
- alter user appadmin
- default tablespace app_space
- /
- create tablespace app_space datafile
- 'd:/app_space01.dbf' size 2M;
- /
- create temporary tablespace mytmp01
- tempfile 'd:/mytmp01_1.dbf' size 4M;
- alter user appadmin temporary tablespace mytmp01;
- /
- create table emp(
- empid number(5) constraint pk_emp primary key,
- name varchar2(20) constraint emp_name not null,
- sal number(5),
- deptid number(3) constraint fk_deptid references dept,
- dutyid number(3) constraint fk_dutyid references duty
- )tablespace app_space;
- /
- select table_name from user_tables;
- select table_name from dba_tables;
- /
- create table dept(
- deptid number(3) constraint pk_dept primary key,
- name varchar2(30) constraint dept_name not null,
- leader number(20) constraint dept_leader not null
- )tablespace app_space;
- /
- create table duty(
- dutyid number(3) constraint pk_duty primary key,
- name varchar2(30) constraint duty_dutyid unique,
- dLevel number(2)
- )tablespace app_space;
- /
- create table cust(
- custid number(5) constraint pk_cust primary key,
- name varchar2(20) constraint cust_name not null,
- tel varchar2(20),
- empid number(5) constraint fk_cust references emp
- )tablespace app_space;
- /
- alter table emp add constraint fk_emp foreign key(deptid)
- references dept(deptid);
- /
- alter table cust add constraint fk_cust foreign key(empid)
- references emp(empid);
- /
- select constraint_name table_name from user_constraint;
- /
- insert into dept values(001,'DEPT',099);
- insert into duty values(010,'设计师',3);
- insert into emp values(1001,'zhao',7000,001,010);
- insert into cust values(10001,'sun',82312549,1001);
- /
- select constraint_name table_name from user_constraints;
- select index_name from user_indexes;
- select table_name from user_tables;
- /
- create index emp_index on emp(empid)
- tablespace app_space;
- /