2 Installing Sample Schemas
Starting with Oracle Database 12c Release 2, the latest version of the sample schema scripts are available on GitHub at https://github.com/oracle/db-sample-schemas/releases/latest.
During a complete installation of Oracle Database, the HR schema can be installed either manually or automatically when creating a database using the dbca option. All the other sample schemas must be installed manually via the scripts available on GitHub.
This chapter contains the following topics:
Note:
By installing any of the Oracle Database sample schemas, you will drop any previously installed schemas that use the following user names: HR, OE, PM, SH, IX, BI.
Data contained in any of these schemas will be lost if you run any of the installation scripts described in this section. You should not use the sample schemas for your personal or business data and applications. They are meant to be used for demonstration purposes only.
2.1 Installing HR Schema Only
This section contains the following topics:
2.1.1 Installing HR Schema Using Database Configuration Assistant
Select the sample schemas option to install HR schema in the database.
At the end of the installation process, a dialog box displays the accounts that have been created and their lock status. By default, sample schemas are locked and their passwords are expired. Before you can use a locked account, you must unlock it and reset its password. You can unlock the accounts at this point in the installation process. Alternatively, after the installation completes, you can unlock the schemas and reset their passwords by using the ALTER USER ... ACCOUNT UNLOCK statement. For example:
ALTER USER hr ACCOUNT UNLOCK IDENTIFIED BY Password;See Also:
"Guidelines for Securing Passwords" in Oracle Database Security Guide for guidelines related to creating secure passwords
2.1.2 Manually Installing the HR Schema
All scripts necessary to create the Human Resource (HR) schema reside in $ORACLE_HOME/demo/schema/human_resources.
You need to call only one script, hr_main.sql, to create all the objects and load the data. The following steps provide a summary of the installation process:
-
Log on to SQL*Plus as
SYSandconnectusing theAS SYSDBAprivilege.sqlplus connect sys as sysdba Enter password:password -
To run the
hr_main.sqlscript, use the following command:SQL> @?/demo/schema/human_resources/hr_main.sql
-
Enter a secure password for
HRspecify password for HR as parameter 1: Enter value for 1:
Enter an appropriate tablespace, for example,
usersas the default tablespace forHRspecify default tablespace for HR as parameter 2: Enter value for 2:
-
Enter
tempas the temporary tablespace forHRspecify temporary tablespace for HR as parameter 3: Enter value for 3:
-
Enter your
SYSpasswordspecify password for SYS as parameter 4: Enter value for 4:
-
Enter the directory path, for example,
$ORACLE_HOME/demo/schema/log/, for your log directoryspecify log path as parameter 5: Enter value for 5:
After script hr_main.sql runs successfully and schema HR is installed, you are connected as user HR. To verify that the schema was created, use the following command:
SQL> SELECT table_name FROM user_tables;
Running hr_main.sql accomplishes the following tasks:
- Removes any previously installed
HRschema - Creates user
HRand grants the necessary privileges - Connects as
HR - Calls the scripts that create and populate the schema objects
For a complete listing of the scripts and their functions, refer to HR Sample Schema Scripts and Objects.
A pair of optional scripts, hr_dn_c.sql and hr_dn_d.sql, is provided as a schema extension. To prepare schema HR for use with the directory capabilities of Oracle Internet Directory, run the hr_dn_c.sql script. If you want to return to the initial setup of schema HR, use script hr_dn_d.sql to undo the effects of script hr_dn_c.sql.
You can use script hr_drop.sql to drop schema HR.
See Also:
Oracle Database Security Guide for the minimum password requirements
2.2 Installing Sample Schemas from GitHub
Starting with Oracle Database 12c Release 2, only the HR sample schema SQL scripts are available in the $ORACLE_HOME/demo/schema/human_resources directory. If you want to use sample schemas other than HR, such as OE, OC, PM, and SH schemas, you must download them from the GitHub repository.
-
To find the latest version of the sample schemas installation scripts, go to the following GitHub web site : https://github.com/oracle/db-sample-schemas/releases/latest
For example, If you want a 12.2.0.1 version of the scripts, then go to https://github.com/oracle/db-sample-schemas/releases/tag/v12.2.0.1
-
Clone the GitHub repository, or download the ZIP bundle from GitHub and extract the files.
-
Unzip the file.
-
Follow the instructions to create the schemas in the README contained in the zip file.
This section includes the following topics:
2.2.1 Resetting Sample Schemas
To reset sample schemas to their initial state, use the following syntax from the SQL*Plus command-line interface:
sqlplus system/systempw@connect_string @mksample systempw syspw hrpw oepw pmpw ixpw shpw bipw users temp /your/path/to/log/ connect_string
The mksample script expects 11 parameters. Provide the password for SYSTEM and SYS, and for schemas HR, OE, PM, IX, and SH. Specify a temporary and a default tablespace, and make sure to end the name of the log file directory with a trailing slash.
The mksample script produces several log files:
-
mkverify.logis the Sample Schema creation log file. -
hr_main.logis theHRschema creation log file. -
oe_oc_main.logis theOEschema creation log file. -
pm_main.logis thePMschema creation log file. -
pm_p_lob.logis the SQL*Loader log file forPM.PRINT_MEDIA. -
ix_main.logis theIXschema creation log file. -
sh_main.logis theSHschema creation log file. -
cust.logis the SQL*Loader log file forSH.CUSTOMERS. -
prod.logis the SQL*Loader log file forSH.PRODUCTS. -
promo.logis the SQL*Loader log file forSH.PROMOTIONS. -
sales.logis the SQL*Loader log file forSH.SALES. -
sales_ext.logis the external table log file forSH.COSTS.
In most situations, there is no difference between installing a Sample Schema for the first time or reinstalling it over a previously installed version. The *_main.sql scripts drop the schema users and all of their objects.
2.2.2 Uninstalling Sample Schemas
If you need to remove the sample schemas from the installation, run script drop_sch.sql on the SQL*Plus command line. This script ships with Oracle Database.
This script uses the following parameters:
-
systempwd -
SYSTEM -
connect_string
The systempwd is the password for SYSTEM user and connect_string is the connection string of the database.
Example 2-1 How to Uninstall Sample Schemas
sqlplus system/systempw@connect_string @drop_sch.sql
2.3 Installing CO schema
Currently, CO schema cannot be installed along with the other schema using the mksample script. Install the CO schema independently from GitHub.
The steps to install CO schema from GitHub is as follows:
Note:
- The Customer Orders(CO) schema is available from Oracle Database 12c onwards.
- The master script
@mksamplecurrently does not include the CO schema.