Files
question_javadb/sql/CreateTable-MySQL.sql
2026-10-28 10:43:56 +09:00

30 lines
1.3 KiB
SQL
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

-- 部署テーブルの作成
DROP TABLE IF EXISTS employee;
DROP TABLE IF EXISTS department;
CREATE TABLE department (
id_department INT AUTO_INCREMENT PRIMARY KEY
, nm_department VARCHAR(10) NOT NULL
);
-- 社員テーブルの作成(Question06から使用)
CREATE TABLE employee (
id_employee INT AUTO_INCREMENT PRIMARY KEY
, nm_employee VARCHAR(50) NOT NULL
, id_department INT NOT NULL
, FOREIGN KEY (id_department) REFERENCES department (id_department)
);
-- 部署テーブルの初期データ
INSERT INTO department (nm_department) VALUES ('営業部');
INSERT INTO department (nm_department) VALUES ('人事部');
INSERT INTO department (nm_department) VALUES ('開発部');
-- 以下の2件は所属する社員がいない部署(削除の演習で使用する)
INSERT INTO department (nm_department) VALUES ('東京支店');
INSERT INTO department (nm_department) VALUES ('大阪支店');
-- 社員テーブルの初期データ(Question06から使用)
INSERT INTO employee (nm_employee, id_department) VALUES ('山田太郎', 1);
INSERT INTO employee (nm_employee, id_department) VALUES ('鈴木花子', 2);
INSERT INTO employee (nm_employee, id_department) VALUES ('佐藤次郎', 3);
INSERT INTO employee (nm_employee, id_department) VALUES ('田中三郎', 1);