The website

SQL Runoob Tutorial
https://www.runoob.com/sqlite/sqlite-tutorial.html

SQL Exercise with Database - the university database schema
https://www.db-book.com/db7/university-lab-dir/sqljs.html

Online SQL Interpreter without demo DB
https://kripken.github.io/sql.js/examples/GUI/index.html

Example

Show the table of SQL Database

  1. select `name`, `sql`
  2. from `sqlite_master`
  3. where type = 'table'

Choose the instructor which the salary is over 10000

  1. select name, salary
  2. from instructor -- From means choose the form
  3. where salary > 10000 -- where means that the conditional statement

The instruction

University DB Data Table

  1. name sql
  2. classroom
  3. CREATE TABLE classroom
  4. (
  5. building varchar(15),
  6. room_number varchar(7),
  7. capacity numeric(4,0),
  8. primary key (building, room_number)
  9. )
  10. department
  11. CREATE TABLE department
  12. (dept_name varchar(20),
  13. building varchar(15),
  14. budget numeric(12,2) check (budget > 0),
  15. primary key (dept_name)
  16. )
  17. course
  18. CREATE TABLE course
  19. (course_id varchar(8),
  20. title varchar(50),
  21. dept_name varchar(20),
  22. credits numeric(2,0) check (credits > 0),
  23. primary key (course_id),
  24. foreign key (dept_name) references department
  25. on delete set null
  26. )
  27. instructor
  28. CREATE TABLE instructor
  29. (ID varchar(5),
  30. name varchar(20) not null,
  31. dept_name varchar(20),
  32. salary numeric(8,2) check (salary > 29000),
  33. primary key (ID),
  34. foreign key (dept_name) references department
  35. on delete set null
  36. )
  37. section
  38. CREATE TABLE section
  39. (course_id varchar(8),
  40. sec_id varchar(8),
  41. semester varchar(6)
  42. check (semester in ('Fall', 'Winter', 'Spring', 'Summer')),
  43. year numeric(4,0) check (year > 1701 and year < 2100),
  44. building varchar(15),
  45. room_number varchar(7),
  46. time_slot_id varchar(4),
  47. primary key (course_id, sec_id, semester, year),
  48. foreign key (course_id) references course
  49. on delete cascade,
  50. foreign key (building, room_number) references classroom
  51. on delete set null
  52. )
  53. teaches
  54. CREATE TABLE teaches
  55. (ID varchar(5),
  56. course_id varchar(8),
  57. sec_id varchar(8),
  58. semester varchar(6),
  59. year numeric(4,0),
  60. primary key (ID, course_id, sec_id, semester, year),
  61. foreign key (course_id,sec_id, semester, year) references section
  62. on delete cascade,
  63. foreign key (ID) references instructor
  64. on delete cascade
  65. )
  66. student
  67. CREATE TABLE student
  68. (ID varchar(5),
  69. name varchar(20) not null,
  70. dept_name varchar(20),
  71. tot_cred numeric(3,0) check (tot_cred >= 0),
  72. primary key (ID),
  73. foreign key (dept_name) references department
  74. on delete set null
  75. )
  76. takes
  77. CREATE TABLE takes
  78. (ID varchar(5),
  79. course_id varchar(8),
  80. sec_id varchar(8),
  81. semester varchar(6),
  82. year numeric(4,0),
  83. grade varchar(2),
  84. primary key (ID, course_id, sec_id, semester, year),
  85. foreign key (course_id,sec_id, semester, year) references section
  86. on delete cascade,
  87. foreign key (ID) references student
  88. on delete cascade
  89. )
  90. advisor
  91. CREATE TABLE advisor
  92. (s_ID varchar(5),
  93. i_ID varchar(5),
  94. primary key (s_ID),
  95. foreign key (i_ID) references instructor (ID)
  96. on delete set null,
  97. foreign key (s_ID) references student (ID)
  98. on delete cascade
  99. )
  100. time_slot
  101. CREATE TABLE time_slot
  102. (time_slot_id varchar(4),
  103. day varchar(1),
  104. start_hr numeric(2) check (start_hr >= 0 and start_hr < 24),
  105. start_min numeric(2) check (start_min >= 0 and start_min < 60),
  106. end_hr numeric(2) check (end_hr >= 0 and end_hr < 24),
  107. end_min numeric(2) check (end_min >= 0 and end_min < 60),
  108. primary key (time_slot_id, day, start_hr, start_min)
  109. )
  110. prereq
  111. CREATE TABLE prereq
  112. (course_id varchar(8),
  113. prereq_id varchar(8),
  114. primary key (course_id, prereq_id),
  115. foreign key (course_id) references course
  116. on delete cascade,
  117. foreign key (prereq_id) references course
  118. )

HR Data Table

  1. name sql
  2. countries
  3. CREATE TABLE countries(
  4. country_id varchar(2) primary key not null,
  5. country_name varchar(40) not null,
  6. region_id integer(2) not null)
  7. regions
  8. CREATE TABLE regions(
  9. region_id integer(2) primary key not null,
  10. region_name varchar(25) not null)
  11. locations
  12. CREATE TABLE locations(
  13. location_id integer(4) primary key not null,
  14. street_address varchar(25) not null,
  15. postal_code varchar(12),
  16. city varchar(30) not null,
  17. state_province varchar(12),
  18. country_id varchar(2))
  19. departments
  20. CREATE TABLE departments(
  21. department_id integer(3) primary key not null,
  22. depart_name varchar(20) not null,
  23. manager_id integer(3) not null,
  24. location_id integer(4))
  25. jobs
  26. CREATE TABLE jobs(
  27. job_id varchar(10) primary key not null,
  28. job_title varchar(25) not null,
  29. min_salary decimal,
  30. max_salary decimal)
  31. employees
  32. CREATE TABLE employees(
  33. employee_id integer(3) primary key not null,
  34. first_name varchar(20),
  35. last_name varchar(25),
  36. email varchar(25),
  37. phone_number varchar(20),
  38. hire_date date,
  39. job_id varchar(10) not null,
  40. salary decimal,
  41. commission_pct number,
  42. manager_id integer(3),
  43. department_id integer(3), Avg_Salary NUMERIC)
  44. department
  45. CREATE TABLE department(
  46. "department_id" TEXT,
  47. "department_name" TEXT,
  48. "manager_id" TEXT,
  49. "location_id" TEXT
  50. )
  51. job_history
  52. CREATE TABLE job_history(
  53. employee_id integer(3) not null,
  54. start_date date not null,
  55. end_date date not null,
  56. job_id varchar(10) not null,
  57. department_id integer(3) not null)
  58. prod_mast
  59. CREATE TABLE prod_mast(
  60. prod_id integer PRIMARY KEY,
  61. prod_name text(20),
  62. prod_rate integer,
  63. prod_qc text(20) DEFAULT 'OK')
  64. prod_backup
  65. CREATE TABLE prod_backup(
  66. prod_id integer PRIMARY KEY,
  67. prod_name text(20),
  68. prod_rate integer,
  69. prod_qc text(10) DEFAULT 'OK')
  70. orders
  71. CREATE TABLE orders(
  72. ord_no integer PRIMARY KEY,
  73. item_id integer ,
  74. item_name text(20),
  75. ord_qty integer,
  76. cost integer)
  77. tb1
  78. CREATE TABLE tb1 (c1 INT, c2 CHAR(5), c3 FLOAT)
  79. ESERCICIO1
  80. CREATE TABLE ESERCICIO1(C TEXT, D TEXT)
  81. users
  82. CREATE TABLE users(name varchar(128), email varchar(128))
  83. tags
  84. CREATE TABLE tags (
  85. title TEXT,
  86. description TEXT,
  87. created TEXT
  88. )
  89. s
  90. CREATE TABLE s( A int, D int, E int)
  91. r
  92. CREATE TABLE r (A int, B int)
  93. Emor
  94. CREATE TABLE Emor(
  95. ID INT PRIMARY KEY NOT NULL,
  96. NAME TEXT)
  97. MIN_SALARY
  98. CREATE TABLE MIN_SALARY(job_id TEXT,MIN_SALARY)
  99. employee_data
  100. CREATE TABLE employee_data (employee_name TEXT, item TEXT, rate REAL, quantity INTEGER, date TEXT, id INTEGER PRIMARY KEY)
  101. STUDENT
  102. CREATE TABLE STUDENT(
  103. ID INT PRIMARY KEY NOT NULL,
  104. NAME TEXT NOT NULL,
  105. AGE INT NOT NULL,
  106. ADDRESS CHAR(50),
  107. FEES REAL
  108. )
  109. EMPLOYEE_INCOME
  110. CREATE TABLE EMPLOYEE_INCOME
  111. (EMPID NUMBER(10),
  112. NAME VARCHAR2(20),
  113. SALARY NUMBER(10))
  114. details CREATE TABLE details
  115. (id number(8,0),
  116. name varchar2(50),
  117. weight number(8,0),
  118. turn number(8,0)
  119. )