

PRIMARY KEY (emp_no, dept_no) - might not be unique? Need from_date Join table to support between many-to-many relationship between employees and departments.

There are 331,603 records for this table.
#Create new mysql database workbench update#
It is more meaningful to set ON UPDATE to CASCADE, so that changes in parent table (e.g., change in emp_no and dept_no) can be cascaded down to the child table(s). The ON UPDATE reference action of is defaulted to RESTRICT (or disallow). There are two reference actions: ON DELETE and ON UPDATE. Take note that the default ON DELETE reference action of is RESTRICTED, which disallows DELETE on the parent record, if there are matching records in the child table. If a record having a particular key-value from the parent table (employees and departments) is deleted, all the records in this child table having the same key-value are also deleted. The foreign keys have ON DELETE reference action of CASCADE. Might not be unique? Need to include from_date involving this emp_no in this child table are also deletedįOREIGN KEY (dept_no) REFERENCES departments (dept_no) ON DELETE CASCADE, If an emp_no is deleted from parent 'employee', all records Cascade DELETE from parent table 'employee' to this child table KEY (dept_no), - Build INDEX on this non-unique-value columnįOREIGN KEY (emp_no) REFERENCES employees (emp_no) ON DELETE CASCADE, KEY (emp_no), - Build INDEX on this non-unique-value column An employee can belong to different department at different dates, and possibly concurrently. Junction table to support between many-to-many relationship between employees and departments. Generally, relational databases are optimized for retrievals, and NOT for modifications. However, they deplete the performance in INSERT, UPDATE and DELETE. An INDEX can be built on unique-value column ( UNIQUE KEY or UNIQUE INDEX) or non-unique-value column ( KEY or INDEX). UNIQUE KEY (dept_name) - Build INDEX on this unique-value column PRIMARY KEY (dept_no), - Index built automatically Table " departments" CREATE TABLE departments (ĭept_no CHAR(4) NOT NULL, - in the form of 'dxxx' There are 300,024 records for this table. PRIMARY KEY (emp_no) - Index built automatically on primary-key column - INDEX (first_name) Gender ENUM ('M','F') NOT NULL, - Enumeration of either 'M' or 'F' There are 6 tables as follows: Table " employees" CREATE TABLE employees (Įmp_no INT NOT NULL, - UNSIGNED AUTO_INCREMENT? This is a rather simple database with 6 tables but with millions of records. Reference: MySQL's Sample Employees Database. There are many excellent and interesting sample databases available, that you can use as a template (or pattern) to design your own databases.
