Summary: in this tutorial, you will learn about a SQL Sample Database called HR that manages the HR data of the small businesses.
The following database diagram illustrates the HR sample database:
The HR sample database has seven tables:
- The
employees
table stores the data of employees. - The
jobs
table stores the job data including job title and salary range. - The
departments
table stores department data. - The
dependents
table stores the employee’s dependents. - The
locations
table stores the location of the departments of the company. - The
countries
table stores the data of countries where the company is doing business. - The
regions
table stores the data of regions such as Asia, Europe, America, and the Middle East and Africa. The countries are grouped into regions.
The following picture shows the table names and their records.
Table | Rows |
---|---|
employees | 40 |
dependents | 30 |
departments | 11 |
jobs | 11 |
locations | 7 |
countries | 25 |
regions | 4 |
Typically, you need to install a Relational Database Management System (RDBMS) to work with SQL.
If you have worked with an RDBMS such as MySQL, PostgreSQL, Oracle Database, and SQL Server, you can use the following script to create the sample database in one of these databases.
In case you don’t have a database system to practice, you can quickly use our SQL online tool to execute the SQL statements in your web browser.
MySQL
The following SQL script creates the HR sample database in MySQL:
Create HR Sample Database in MySQLThe following script allows you to insert data into the tables in MySQL:
Load HR Data in MySQLPostgreSQL
The following script creates the HR sample database structure in PostgreSQL.
Create HR Sample Database in PostgreSQLThe following script allows you to insert data into the tables in PostgreSQL:
Load HR Data in PostgreSQLMicrosoft SQL Server
The following script creates the HR sample database structure in Microsoft SQL Server.
Create HR Sample Database in SQL ServerThe following script allows you to insert data into the tables:
Load HR Data in SQL ServerOracle Database (>12c)
The following script creates the HR sample database structure in Oracle Database 12c.
Create HR Sample Database in OracleThe following script inserts data into the tables in the Oracle database:
Load HR Data in Oracle DatabaseSQLite
The following script creates the HR sample database structure in SQLite.
Create HR Sample Database in SQLiteThe following script inserts data into the tables in the SQLite:
Create HR Sample Database in SQLiteRemoving tables
The following is the script that drops all tables in case you want to refresh the sample database.
Drop All Tables