SQL script
DROP DATABASE IF EXISTS FullStackDev;
CREATE DATABASE IF NOT EXISTS FullStackDev;
USE FullStackDev;
-- Create table Department --
DROP TABLE IF EXISTS `Department`;
CREATE TABLE IF NOT EXISTS `Department` (
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
`name` VARCHAR(50) NOT NULL UNIQUE,
total_member INT UNSIGNED,
created_date DATETIME DEFAULT NOW()
);
-- Create table Account ---
DROP TABLE IF EXISTS `Account`;
CREATE TABLE IF NOT EXISTS `Account` (
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
username VARCHAR(50) NOT NULL UNIQUE KEY,
department_id INT UNSIGNED NOT NULL,
FOREIGN KEY(department_id) REFERENCES Department(id)
);
INSERT INTO Department(`name`, total_member)
VALUES ('Marketing', 3),
('Sale', 4),
('CS', 6),
('Security', 6),
('Dev', 20);
INSERT INTO `Account` (username, department_id)
VALUES ('thachphamdev', 5),
('jadeengineer', 5),
('johncenar', 3),
('peter', 1),
('carlos', 2),
('finazos', 3),
('hiana', 4),
('pleasesubscribe', 1),
('pleaselike', 2),
('gammer', 5);
Comments
Post a Comment