初学sql的时候经常使用SCOTT模式中的演示对象做为测试.你的数据库里可能已经有 SCOTT/TIGER 模式(schema)了。经典安装通常就包括这个模式,不过并不要求数据库一定得有这个组件。可以把 SCOTT 示例模式安装到任何数据库账户下,使用 SCOTT 账户并没有特殊的意义。如果乐意,你还可以把 EMP/DEPT 表直接安装在你自己的数据库账户下。
要创建 SCOTT 演示表,步骤很简单:
(1)cd [ORACLE_HOME]/sqlplus/demo。
如: [oracle@q1test01 ~]$ ls $ORACLE_HOME/sqlplus/demo
demobld.sql demodrop.sql
(2)以任意用户身份连接后运行 demobld.sql (注意 用哪个用记运行demobld.sql,SCOTT演示表当然就建立在哪个用记下).我是计划把它建立在SCOTT.故要先建立SCOTT些用户.
SQL> create user scott identified by tiger default tablespace users temporary tablespace temp2;
SQL> grant resource,connect to scott;
SQL> conn scott/tiger
SQL> show user
USER is "SCOTT"
SQL> @$ORACLE_HOME/sqlplus/demo/demobld.sql
Building demonstration tables. Please wait.
Demonstration table build is complete.
Disconnected from Oracle9i Enterprise Edition Release 9.2.0.7.0 - 64bit Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.7.0 – Production
demobld.sql 会创建 5 个表并填入数据。执行结束后,它会自动退出 SQL*Plus,所以运行完这个脚本后 SQL*Plus 窗口将消失,对此不要感到奇怪,这是正常的。
这些标准演示表上没有定义任何引用完整性,但后面有些例子要求表必须有引用完整性,所以运行完demobld.sql 后,建议你再执行以下脚本:
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 个演示表,并退出 SQL*Plus。
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/12045182/viewspace-345700/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/12045182/viewspace-345700/