SQLize Online / PHPize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
CREATE TABLE `WORKERS` ( `Id_worker` INT(6) NOT NULL AUTO_INCREMENT, `Name` varchar(25) NOT NULL, `Surname` varchar(25) NOT NULL, `Role` INT(1) NOT NULL, `Username` varchar(25) NOT NULL UNIQUE, `Password` varchar(25) NOT NULL, `Password_changed` INT(1) NOT NULL DEFAULT '0', `Date_born` DATE NOT NULL, `Mail` varchar(255) NOT NULL, PRIMARY KEY (`Id_worker`) ); CREATE TABLE `CUSTOMERS` ( `Vat_number` varchar(25) NOT NULL, `Name` varchar(255) NOT NULL, `Address` varchar(100) NOT NULL, `Location` varchar(25) NOT NULL, `Country` varchar(25) NOT NULL, `Date` DATE NOT NULL, PRIMARY KEY (`Vat_number`) ); CREATE TABLE `CUSTOMERS_REGISTRED` ( `Vat_number` varchar(25) NOT NULL, `Id_worker` INT(6) NOT NULL ); CREATE TABLE `ROBOTS` ( `Serial_number` varchar(25) NOT NULL UNIQUE, `Production_batch` varchar(25) NOT NULL, `Code` varchar(25) NOT NULL, `Weight` DECIMAL(10) NOT NULL, PRIMARY KEY (`Serial_number`) ); CREATE TABLE `ROBOT_FEATURES` ( `Serial_number` varchar(25) NOT NULL, `Berable_weight` DECIMAL(10) NOT NULL, `Cut_resistance` DECIMAL(10) NOT NULL, `Compression` DECIMAL(10) NOT NULL, `Torque` DECIMAL(10) NOT NULL ); CREATE TABLE `ROBOT_SELLED` ( `Serial_number` varchar(25) NOT NULL, `Vat_number` varchar(25) NOT NULL, `Date` DATE NOT NULL ); CREATE TABLE `ROBOTS_WORK` ( `Serial_number` varchar(25) NOT NULL, `Id_worker` INT(6) NOT NULL, `Work` varchar(255) NOT NULL, `State_decay` INT(2) NOT NULL, `Date_work` DATETIME NOT NULL ); ALTER TABLE `CUSTOMERS_REGISTRED` ADD CONSTRAINT `CUSTOMERS_REGISTRED_fk0` FOREIGN KEY (`Vat_number`) REFERENCES `CUSTOMERS`(`Vat_number`); ALTER TABLE `CUSTOMERS_REGISTRED` ADD CONSTRAINT `CUSTOMERS_REGISTRED_fk1` FOREIGN KEY (`Id_worker`) REFERENCES `WORKERS`(`Id_worker`); ALTER TABLE `ROBOT_FEATURES` ADD CONSTRAINT `ROBOT_FEATURES_fk0` FOREIGN KEY (`Serial_number`) REFERENCES `ROBOTS`(`Serial_number`); ALTER TABLE `ROBOT_SELLED` ADD CONSTRAINT `ROBOT_SELLED_fk0` FOREIGN KEY (`Serial_number`) REFERENCES `ROBOTS`(`Serial_number`); ALTER TABLE `ROBOT_SELLED` ADD CONSTRAINT `ROBOT_SELLED_fk1` FOREIGN KEY (`Vat_number`) REFERENCES `CUSTOMERS`(`Vat_number`); ALTER TABLE `ROBOTS_WORK` ADD CONSTRAINT `ROBOTS_WORK_fk0` FOREIGN KEY (`Serial_number`) REFERENCES `ROBOTS`(`Serial_number`); -- ALTER TABLE `ROBOTS_WORK` ADD CONSTRAINT `ROBOTS_WORK_fk1` FOREIGN KEY (`Id_worker`) REFERENCES `WORKERS`(`Id_worker`); INSERT INTO ROBOTS ( Serial_number, Production_batch, Code, Weight ) VALUES ( 'SN0000272865XYZ567890A324', '567809', 'er45', '550' ); INSERT INTO ROBOT_FEATURES ( Serial_number, Berable_weight, Cut_resistance, Compression, Torque ) VALUES ( 'SN0000272865XYZ567890A324', '750', '45', '36', '5' ); INSERT INTO ROBOTS_WORK ( Serial_number, Id_Worker, Work, State_decay, Date_work ) VALUES ( 'SN0000272865XYZ567890A324', '3', 'Installation', '100', '2022-04-16 12:41:05' );

Stuck with a problem? Got Error? Ask ChatGPT!

Copy Clear