重建SCOTT用户及SCOTT轶事(一)

2015-07-16 12:08:10 · 作者: · 浏览: 20

1.scott用户简介
SCOTT是在Oracle数据库中,一个示例用户的名称。其作用是为初学者提供一些简单的应用示例,不过其默认是锁定状态。SCOTT的缺省口令为tiger,下面有表emp, dept等,这些表和表间的关系演示了关系型数据库的一些基本原理,Oracle举例说明时一般都用这个用户,一些关于Oracle的书、教材上一般也都用这个用户来讲解。它对于Oracle本身不是必须的,如果不想用可以删除(如果你没在它下面建其它对象的话)。


2.环境准备
我们在Oracle 10g中进行试验,把scott用户删除。


点击(此处)折叠或打开


C:\\Users\\Administrator>sqlplus sys/hoegh as sysdba


SQL*Plus: Release 10.2.0.4.0 - Production on 星期三 5月 13 10:24:10 2015


Copyright (c) 1982, 2007, Oracle. All Rights Reserved.


连接到:


Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production


With the Partitioning, OLAP, Data Mining and Real Application Testing options


SQL>


SQL>


SQL> select * from v$version;


BANNER


----------------------------------------------------------------


Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi


PL/SQL Release 10.2.0.4.0 - Production


CORE 10.2.0.4.0 Production


TNS for 64-bit Windows: Version 10.2.0.4.0 - Production


NLSRTL Version 10.2.0.4.0 - Production


SQL>


SQL> drop user scott cascade;


用户已删除。


SQL>


3.重建scott用户
Oracle提供了scott用户的重建脚本,脚本位于ORACLE_HOME\RDBMS\ADMIN目录下,脚本名称为utlsampl.sql。我们在sys用户下执行该脚本,如下:


SQL>
?
SQL> show user


USER 为 \"SYS\"


SQL>


SQL> @C:\\oracle\\product\\10.2.0\\db_1\\RDBMS\\ADMIN\\utlsampl.sql


从 Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production


With the Partitioning, OLAP, Data Mining and Real Application Testing options 断



C:\\Users\\Administrator>
执行完脚本后,系统会自动推出sql*plus。接下来我们连接scott用户,确认脚本是否执行成功。


C:\\Users\\Administrator>sqlplus scott/tiger


SQL*Plus: Release 10.2.0.4.0 - Production on 星期三 5月 13 10:34:29 2015


Copyright (c) 1982, 2007, Oracle. All Rights Reserved.


连接到:


Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production


With the Partitioning, OLAP, Data Mining and Real Application Testing options


SQL> select * from cat;


TABLE_NAME TABLE_TYPE


------------------------------ -----------


DEPT TABLE


EMP TABLE


BONUS TABLE


SALGRADE TABLE


SQL> select * from dept;


? ? DEPTNO DNAME LOC


---------- -------------- -------------


? ? ? ? 10 ACCOUNTING NEW YORK


? ? ? ? 20 RESEARCH DALLAS


? ? ? ? 30 SALES CHICAGO


? ? ? ? 40 OPERATIONS BOSTON


SQL>


SQL>


4.utlsampl.sql脚本内容
在ORACLE_HOME\RDBMS\ADMIN目录下有很多脚本,utlsampl.sql只是其中一个。感兴趣的话,看看这些脚本也会有收获的。在这儿我们看一下utlsampl.sql脚本的内容。


Rem Copyright (c) 1990, 1996, 1997, 1999, 2001 by Oracle Corporation
Rem NAME
REM UTLSAMPL.SQL
Rem FUNCTION
Rem NOTES
Rem MODIFIED
Rem menash 02/21/01 - remove unnecessary users for security reasons
Rem gwood 03/23/99 - make all dates Y2K compliant
Rem jbellemo 02/27/97 - dont connect as system
Rem akolk 08/06/96 - bug 368261: Adding date formats
Rem glumpkin 10/21/92 - Renamed from SQLBLD.SQL
Rem blinden 07/27/92 - Added primary and foreign keys to EMP and DEPT
Rem rlim 04/29/91 - change char to varchar2
Rem mmoore 04/08/91 - use unlimited tablespace priv
Rem pritto 04/04/91 - change SYSDATE to 13-JUL-87
Rem Mendels 12/07/90 - bug 30123;add to_date calls so language independent
Rem
rem
rem $Header: utlsampl.sql 21-feb-01.18:15:30 menash Exp $ sqlbld.sql
rem
SET TERMOUT OFF
SET ECHO OFF


rem CONGDON Invoked in RDBMS at build time. 29-DEC-1988
rem OATES: Created: 16-Feb-83


DROP USER SCOTT CASCADE;
DROP USER ADAMS CASCADE;
DROP USER JONES CASCADE;
DROP USER CLARK CASCADE;
DROP USER BLAKE CASCADE;
GRANT CONNECT,RESOURCE,UNLIMITED TABLESPACE TO SCOTT IDENTIFIED BY TIGER;
DROP PUBLIC SYNONYM PARTS;


CONNECT SCOTT/TIGER
CREATE TABLE DEPT
(DEPTNO NUMBER(2) CONSTRAINT PK_DEPT PRIMARY