1 - Create Table (Updated)
1 - Create Table (Updated)
+------------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------+--------------+------+-----+---------+-------+
| JOB_ID | varchar(10) | NO | PRI | | |
| JOB_TITLE | varchar(35) | NO | | NULL | |
| MIN_SALARY | decimal(6,0) | YES | | NULL | |
| MAX_SALARY | decimal(6,0) | YES | | NULL | |
+------------+--------------+------+-----+---------+-------+
17. Write a SQL statement to create a table employees including columns
employee_id, first_name, last_name, job_id, salary and make sure that, the
employee_id column does not contain any duplicate value at the time of
insertion, and the foreign key column job_id, referenced by the column job_id of
jobs table, can contain only those values which are exists in the jobs table. The
InnoDB Engine have been used to create the tables. The specialty of the
statement is that, The ON UPDATE CASCADE action allows you to perform
cross-table update and ON DELETE RESTRICT action reject the deletion. The
default action is ON DELETE RESTRICT.
Assume that the structure of the table jobs and InnoDB Engine have been used
to create the table jobs.
CREATE TABLE IF NOT EXISTS jobs (
JOB_ID integer NOT NULL UNIQUE PRIMARY KEY,
JOB_TITLE varchar(35) NOT NULL DEFAULT ' ',
MIN_SALARY decimal(6,0) DEFAULT 8000,
MAX_SALARY decimal(6,0) DEFAULT NULL
)ENGINE=InnoDB;
+------------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------+--------------+------+-----+---------+-------+
| JOB_ID | int(11) | NO | PRI | NULL | |
| JOB_TITLE | varchar(35) | NO | | | |
| MIN_SALARY | decimal(6,0) | YES | | 8000 | |
| MAX_SALARY | decimal(6,0) | YES | | NULL | |
+------------+--------------+------+-----+---------+-------+
18. Write a SQL statement to create a table employees including columns
employee_id, first_name, last_name, job_id, salary and make sure that, the
employee_id column does not contain any duplicate value at the time of
insertion, and the foreign key column job_id, referenced by the column job_id of
jobs table, can contain only those values which are exists in the jobs table. The
InnoDB Engine have been used to create the tables. The specialty of the
statement is that, The ON DELETE CASCADE that lets you allow to delete
records in the employees(child) table that refer to a record in the jobs(parent)
table when the record in the parent table is deleted and the ON UPDATE
RESTRICT actions reject any updates.
Assume that the structure of the table jobs and InnoDB Engine have been used
to create the table jobs.
CREATE TABLE IF NOT EXISTS jobs (
JOB_ID integer NOT NULL UNIQUE PRIMARY KEY,
JOB_TITLE varchar(35) NOT NULL DEFAULT ' ',
MIN_SALARY decimal(6,0) DEFAULT 8000,
MAX_SALARY decimal(6,0) DEFAULT NULL
)ENGINE=InnoDB;
+------------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------+--------------+------+-----+---------+-------+
| JOB_ID | int(11) | NO | PRI | NULL | |
| JOB_TITLE | varchar(35) | NO | | | |
| MIN_SALARY | decimal(6,0) | YES | | 8000 | |
| MAX_SALARY | decimal(6,0) | YES | | NULL | |
+------------+--------------+------+-----+---------+-------+
19. Write a SQL statement to create a table employees including columns
employee_id, first_name, last_name, job_id, salary and make sure that, the
employee_id column does not contain any duplicate value at the time of
insertion, and the foreign key column job_id, referenced by the column job_id of
jobs table, can contain only those values which are exists in the jobs table. The
InnoDB Engine have been used to create the tables. The specialty of the
statement is that, The ON DELETE SET NULL action will set the foreign key
column values in the child table(employees) to NULL when the record in the
parent table(jobs) is deleted, with a condition that the foreign key column in the
child table must accept NULL values and the ON UPDATE SET NULL action
resets the values in the rows in the child table(employees) to NULL values when
the rows in the parent table(jobs) are updated.
Assume that the structure of two table jobs and InnoDB Engine have been used
to create the table jobs.
CREATE TABLE IF NOT EXISTS jobs (
JOB_ID integer NOT NULL UNIQUE PRIMARY KEY,
JOB_TITLE varchar(35) NOT NULL DEFAULT ' ',
MIN_SALARY decimal(6,0) DEFAULT 8000,
MAX_SALARY decimal(6,0) DEFAULT NULL
)ENGINE=InnoDB;
+------------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------+--------------+------+-----+---------+-------+
| JOB_ID | int(11) | NO | PRI | NULL | |
| JOB_TITLE | varchar(35) | NO | | | |
| MIN_SALARY | decimal(6,0) | YES | | 8000 | |
| MAX_SALARY | decimal(6,0) | YES | | NULL | |
+------------+--------------+------+-----+---------+-------+
20. Write a SQL statement to create a table employees including columns
employee_id, first_name, last_name, job_id, salary and make sure that, the
employee_id column does not contain any duplicate value at the time of
insertion, and the foreign key column job_id, referenced by the column job_id of
jobs table, can contain only those values which are exists in the jobs table. The
InnoDB Engine have been used to create the tables. The specialty of the
statement is that, The ON DELETE NO ACTION and the ON UPDATE NO
ACTION actions will reject the deletion and any updates.
Assume that the structure of two table jobs and InnoDB Engine have been used
to create the table jobs.
CREATE TABLE IF NOT EXISTS jobs (
JOB_ID integer NOT NULL UNIQUE PRIMARY KEY,
JOB_TITLE varchar(35) NOT NULL DEFAULT ' ',
MIN_SALARY decimal(6,0) DEFAULT 8000,
MAX_SALARY decimal(6,0) DEFAULT NULL
)ENGINE=InnoDB;
+------------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------+--------------+------+-----+---------+-------+
| JOB_ID | int(11) | NO | PRI | NULL | |
| JOB_TITLE | varchar(35) | NO | | | |
| MIN_SALARY | decimal(6,0) | YES | | 8000 | |
| MAX_SALARY | decimal(6,0) | YES | | NULL | |
+------------+--------------+------+-----+---------+-------+