o1-手动创建scott(tiger) schema演示表

来源:互联网 发布:淘宝黑莓哪家好 编辑:程序博客网 时间:2024/06/05 20:01

DBA登陆数据库

[oracle@localhost ~]$ sqlplus / as sysdbaSQL*Plus: Release 10.2.0.1.0 - Production on Tue May 8 14:02:38 2012Copyright (c) 1982, 2005, Oracle.  All rights reserved.Connected to:Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - ProductionWith the Partitioning, OLAP and Data Mining options


创建scott用户并授予角色,至于connect和resource权限具体看这里

SQL> create user scott identified by tiger;User created.SQL> grant connect,resource to scott;Grant succeeded.

使用scott用户登陆

SQL> conn scott/tigerConnected.

执行demobld.sql脚本

  • 在oracle 9i中,demobld.sql脚本位于 <ORACLE_HOME>/sqlplus/demo 目录中
  • 在oracle10g中,这个脚本在单独的光盘"Oracle Database 10g Companion CD Release 2"中,可以从otn下载安装。或者手工创建这个文件,文章后面有个附件。


  • SQL> @/home/oracle/Desktop/demobld.sqlBuilding demonstration tables.  Please wait.Demonstration table build is complete.

    这样创建的演示表中没有关联关系,没有引用完整性,其次可以执行以下脚本

    SQL> alter table emp add constraint emp_pk primary key(empno);Table altered.SQL> alter table dept add constraint dept_pk primary key(deptno);Table altered.SQL> alter table emp add constraint emp_fk_dept foreign key(deptno) references dept;Table altered.SQL> alter table emp add constraint emp_fk_emp foreign key(mgr) references emp;Table altered.

    这就完成了演示模式的安装。如果以后你整理系统时删除这个模式,只需执行[ORACLE_HOME]/sqlplus/demo/demodrop.sql(后面有附件)。这个脚本会删除5个演示表

    你也可以直接将此用户删除,语句为

    drop user scott cascade;

    这样写的特点是:

    cascade将会删除scott所拥有的所有对象。
    执行前要确保scott用户没有连接,否则报错。
    你要谨慎,drop之前最好先执行一次导出。