SQL Sample Database

SQL Sample Database

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:

SQL Sample Database Schema

The HR sample database has seven tables:

  1. The employees table stores the data of employees.
  2. The jobs table stores the job data including job title and salary range.
  3. The departments table stores department data.
  4. The dependents table stores the employee’s dependents.
  5. The locations table stores the location of the departments of the company.
  6. The countries table stores the data of countries where the company is doing business.
  7. 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.

TableRows
employees40
dependents30
departments11
jobs11
locations7
countries25
regions4

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 MySQL

The following script allows you to insert data into the tables in MySQL:

Load HR Data in MySQL

PostgreSQL

The following script creates the HR sample database structure in PostgreSQL.

Create HR Sample Database in PostgreSQL

The following script allows you to insert data into the tables in PostgreSQL:

Load HR Data in PostgreSQL

Microsoft SQL Server

The following script creates the HR sample database structure in Microsoft SQL Server.

Create HR Sample Database in SQL Server

The following script allows you to insert data into the tables:

Load HR Data in SQL Server

Oracle Database (>12c)

The following script creates the HR sample database structure in Oracle Database 12c.

Create HR Sample Database in Oracle

The following script inserts data into the tables in the Oracle database:

Load HR Data in Oracle Database

SQLite

The following script creates the HR sample database structure in SQLite.

Create HR Sample Database in SQLite

The following script inserts data into the tables in the SQLite:

Create HR Sample Database in SQLite

Removing tables

The following is the script that drops all tables in case you want to refresh the sample database.

Drop All Tables

Popular posts from this blog

SQL Syntax

SQL FETCH

SQL LIMIT