How to add scott users and related tables in Oracle Database

Source: Internet
Author: User

We know that,Scott userYesOracleAn example user in the database has tables emp and dept. The relationship between these tables and tables demonstrates some basic principles of relational databases. Because it is not a required user, it can be deleted. But what should I do if I want to use scott's user to do experiments and exercises? This article describes how to add a sample scott user and related tables.

The method is as follows:

1. Run the RDBMS \ ADMIN \ utlsampl. SQL script.

2. Check whether the operation is successful.

Example:

 
 
  1. SQL> @ D: \ oracle \ product \ 10.2.0 \ db_1 \ RDBMS \ ADMIN \ utlsampl
  2.  
  3. Disconnected from Oracle Database 10g Release 10.2.0.1.0-Production
  4.  
  5. C: \ Users \ Administrator> sqlplus/as sysdba
  6.  
  7. SQL * Plus: Release 10.2.0.1.0-Production on Saturday July 30 11:55:21 2011
  8.  
  9. Copyright (c) 1982,200 5, Oracle. All rights reserved.
  10.  
  11. Connect:
  12.  
  13. Oracle Database 10g Release 10.2.0.1.0-Production
  14.  
  15. SQL> select * from dba_users where username = 'Scott ';

PS: attach information such as creating scott related tables, data, and permissions

 
 
  1. Rem Copyright (c) 1990, 1996, 1997, 1999, 2001 by Oracle Corporation    
  2.  
  3. Rem NAME    
  4.  
  5. REM    UTLSAMPL.SQL    
  6.  
  7. Rem  FUNCTION    
  8.  
  9. Rem  NOTES    
  10.  
  11. Rem  MODIFIED    
  12.  
  13. Rem     menash     02/21/01 -  remove unnecessary users for security reasons    
  14.  
  15. Rem     gwood      03/23/99 -  make all dates Y2K compliant    
  16.  
  17. Rem     jbellemo   02/27/97 -  dont connect as system    
  18.  
  19. Rem     akolk      08/06/96 -  bug 368261: Adding date formats    
  20.  
  21. Rem     glumpkin   10/21/92 -  Renamed from SQLBLD.SQL     
  22.  
  23. Rem     blinden   07/27/92 -  Added primary and foreign keys to EMP and DEPT    
  24.  
  25. Rem     rlim       04/29/91 -         change char to varchar2     
  26.  
  27. Rem     mmoore     04/08/91 -         use unlimited tablespace priv     
  28.  
  29. Rem     pritto     04/04/91 -         change SYSDATE to 13-JUL-87     
  30.  
  31. Rem   Mendels    12/07/90 - bug 30123;add to_date calls so language independent    
  32.  
  33. Rem    
  34.  
  35. rem     
  36.  
  37. rem $Header: utlsampl.sql 21-feb-01.18:15:30 menash Exp $ sqlbld.sql     
  38.  
  39. rem     
  40.  
  41. SET TERMOUT OFF    
  42.  
  43. SET ECHO OFF    
  44.  
  45. rem CONGDON    Invoked in RDBMS at build time.   29-DEC-1988    
  46.  
  47. rem OATES:     Created: 16-Feb-83    
  48.  
  49. DROP USER SCOTT CASCADE;    
  50.  
  51. DROP USER ADAMS CASCADE;    
  52.  
  53. DROP USER JONES CASCADE;    
  54.  
  55. DROP USER CLARK CASCADE;    
  56.  
  57. DROP USER BLAKE CASCADE;    
  58.  
  59. GRANT CONNECT,RESOURCE,UNLIMITED TABLESPACE TO SCOTT IDENTIFIED BY TIGER;    
  60.  
  61. DROP PUBLIC SYNONYM PARTS;    
  62.  
  63. CONNECT SCOTT/TIGER    
  64.  
  65. CREATE TABLE DEPT    
  66.  
  67. (DEPTNO NUMBER(2) CONSTRAINT PK_DEPT PRIMARY KEY,    
  68.  
  69. DNAME VARCHAR2(14) ,    
  70.  
  71. LOC VARCHAR2(13) ) ;    
  72.  
  73. CREATE TABLE EMP    
  74.  
  75. (EMPNO NUMBER(4) CONSTRAINT PK_EMP PRIMARY KEY,    
  76.  
  77. ENAME VARCHAR2(10),    
  78.  
  79. JOB VARCHAR2(9),    
  80.  
  81. MGR NUMBER(4),    
  82.  
  83. HIREDATE DATE,    
  84.  
  85. SAL NUMBER(7,2),    
  86.  
  87. COMM NUMBER(7,2),    
  88.  
  89. DEPTNO NUMBER(2) CONSTRAINT FK_DEPTNO REFERENCES DEPT);    
  90.  
  91. INSERT INTO DEPT VALUES    
  92.  
  93. (10,'ACCOUNTING','NEW YORK');    
  94.  
  95. INSERT INTO DEPT VALUES (20,'RESEARCH','DALLAS');    
  96.  
  97. INSERT INTO DEPT VALUES    
  98.  
  99. (30,'SALES','CHICAGO');    
  100.  
  101. INSERT INTO DEPT VALUES    
  102.  
  103. (40,'OPERATIONS','BOSTON');    
  104.  
  105. INSERT INTO EMP VALUES    
  106.  
  107. (7369,'SMITH','CLERK',7902,to_date('17-12-1980','dd-mm-yyyy'),800,NULL,20);    
  108.  
  109. INSERT INTO EMP VALUES    
  110.  
  111. (7499,'ALLEN','SALESMAN',7698,to_date('20-2-1981','dd-mm-yyyy'),1600,300,30);    
  112.  
  113. INSERT INTO EMP VALUES    
  114.  
  115. (7521,'WARD','SALESMAN',7698,to_date('22-2-1981','dd-mm-yyyy'),1250,500,30);    
  116.  
  117. INSERT INTO EMP VALUES    
  118.  
  119. (7566,'JONES','MANAGER',7839,to_date('2-4-1981','dd-mm-yyyy'),2975,NULL,20);    
  120.  
  121. INSERT INTO EMP VALUES    
  122.  
  123. (7654,'MARTIN','SALESMAN',7698,to_date('28-9-1981','dd-mm-yyyy'),1250,1400,30);    
  124.  
  125. INSERT INTO EMP VALUES    
  126.  
  127. (7698,'BLAKE','MANAGER',7839,to_date('1-5-1981','dd-mm-yyyy'),2850,NULL,30);    
  128.  
  129. INSERT INTO EMP VALUES    
  130.  
  131. (7782,'CLARK','MANAGER',7839,to_date('9-6-1981','dd-mm-yyyy'),2450,NULL,10);    
  132.  
  133. INSERT INTO EMP VALUES    
  134.  
  135. (7788,'SCOTT','ANALYST',7566,to_date('13-JUL-87','dd-mm-rr')-85,3000,NULL,20);    
  136.  
  137. INSERT INTO EMP VALUES    
  138.  
  139. (7839,'KING','PRESIDENT',NULL,to_date('17-11-1981','dd-mm-yyyy'),5000,NULL,10);    
  140.  
  141. INSERT INTO EMP VALUES    
  142.  
  143. (7844,'TURNER','SALESMAN',7698,to_date('8-9-1981','dd-mm-yyyy'),1500,0,30);    
  144.  
  145. INSERT INTO EMP VALUES    
  146.  
  147. (7876,'ADAMS','CLERK',7788,to_date('13-JUL-87', 'dd-mm-rr')-51,1100,NULL,20);    
  148.  
  149. INSERT INTO EMP VALUES    
  150.  
  151. (7900,'JAMES','CLERK',7698,to_date('3-12-1981','dd-mm-yyyy'),950,NULL,30);    
  152.  
  153. INSERT INTO EMP VALUES    
  154.  
  155. (7902,'FORD','ANALYST',7566,to_date('3-12-1981','dd-mm-yyyy'),3000,NULL,20);    
  156.  
  157. INSERT INTO EMP VALUES    
  158.  
  159. (7934,'MILLER','CLERK',7782,to_date('23-1-1982','dd-mm-yyyy'),1300,NULL,10);    
  160.  
  161. CREATE TABLE BONUS    
  162.  
  163. (    
  164.  
  165. ENAME VARCHAR2(10)  ,    
  166.  
  167. JOB VARCHAR2(9)  ,    
  168.  
  169. SAL NUMBER,    
  170.  
  171. COMM NUMBER    
  172.  
  173. ) ;    
  174.  
  175. CREATE TABLE SALGRADE    
  176.  
  177. ( GRADE NUMBER,    
  178.  
  179. LOSAL NUMBER,    
  180.  
  181. HISAL NUMBER );    
  182.  
  183. INSERT INTO SALGRADE VALUES (1,700,1200);    
  184.  
  185. INSERT INTO SALGRADE VALUES (2,1201,1400);    
  186.  
  187. INSERT INTO SALGRADE VALUES (3,1401,2000);    
  188.  
  189. INSERT INTO SALGRADE VALUES (4,2001,3000);    
  190.  
  191. INSERT INTO SALGRADE VALUES (5,3001,9999);    
  192.  
  193. COMMIT;    
  194.  
  195. EXIT  

After following the steps above, we can successfully Add the scott user and related tables of the sample data. This article will introduce them here and hope to help you gain some benefits!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.