Hi! Could we please enable some services and cookies to improve your experience and our website?

SQLize Online / PHPize Online  /  SQLtest Online

A A A
Share      Blog   Popular

SQLize.online is a free online SQL environment for quickly running, experimenting with and sharing code. You can run your SQL code on top of the most popular RDBMS including MySQL, MariaDB, SQLite, PostgreSQL, Oracle and Microsoft SQL Server.

Copy Format Clear
-- Create Countries Table CREATE TABLE Countries ( country_id CHAR(2) PRIMARY KEY, country_name VARCHAR(40), region_id INT, FOREIGN KEY (region_id) REFERENCES Regions(region_id) ); -- Create Departments Table CREATE TABLE Departments ( department_id INT PRIMARY KEY, department_name VARCHAR(30), manager_id INT, location_id INT, FOREIGN KEY (location_id) REFERENCES Locations(location_id) ); -- Create Locations Table CREATE TABLE Locations ( location_id INT PRIMARY KEY, street_address VARCHAR(40), postal_code VARCHAR(12), city VARCHAR(30), state_province VARCHAR(25), country_id CHAR(2), FOREIGN KEY (country_id) REFERENCES Countries(country_id) ); -- Create Jobs Table CREATE TABLE Jobs ( job_id VARCHAR(10) PRIMARY KEY, job_title VARCHAR(35), min_salary DECIMAL(8, 2), max_salary DECIMAL(8, 2) ); -- Create Regions Table CREATE TABLE Regions ( region_id INT PRIMARY KEY, region_name VARCHAR(50) ); -- Create Job_history Table CREATE TABLE Job_history ( employee_id INT, start_date DATE, end_date DATE, job_id VARCHAR(10), department_id INT, PRIMARY KEY (employee_id, start_date), FOREIGN KEY (employee_id) REFERENCES Employees(employee_id), FOREIGN KEY (job_id) REFERENCES Jobs(job_id), FOREIGN KEY (department_id) REFERENCES Departments(department_id) ); -- Create Employees Table CREATE TABLE Employees ( employee_id INT PRIMARY KEY, first_name VARCHAR(20), last_name VARCHAR(25), email VARCHAR(25), phone_number VARCHAR(20), hire_date DATE, job_id VARCHAR(10), salary DECIMAL(8, 2), commission_pct DECIMAL(2, 2), manager_id INT, department_id INT, FOREIGN KEY (job_id) REFERENCES Jobs(job_id), FOREIGN KEY (manager_id) REFERENCES Employees(employee_id), FOREIGN KEY (department_id) REFERENCES Departments(department_id) );

Stuck with a problem? Got Error? Ask ChatGPT!

Copy Clear