SQLize Online / PHPize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
create table staff like sakila.staff; insert into staff select * from sakila.staff; create table department ( department_id int auto_increment primary key , name varchar(64) ); insert into department (name) values ('Management'),('Sales'); ; ALTER TABLE staff ADD COLUMN department_id INT; ALTER TABLE staff ADD CONSTRAINT fk_department FOREIGN KEY (department_id) REFERENCES department(department_id); UPDATE staff SET department_id = (SELECT department_id FROM department WHERE name = 'Sales'); ; select staff_id, department_id from staff;

Stuck with a problem? Got Error? Ask ChatGPT!

Copy Clear