-- SQL dump generated using DBML (dbml-lang.org) -- Database: MySQL -- Generated at: 2023-07-09T17:21:24.446Z CREATE TABLE `users` ( `id` bigint unsigned PRIMARY KEY AUTO_INCREMENT, `rank` ENUM ('Capitaine', 'Lieutenant', 'Sous-Lieutenant', 'Aspirant', 'Major', 'Adjudant-Chef', 'Adjudant', 'Sergent-Chef BM2', 'Sergent-Chef', 'Sergent', 'Caporal-Chef de première classe', 'Caporal-Chef', 'Caporal', 'Première classe', 'Marsouin'), `isFirstLogin` boolean NOT NULL, `isAdmin` boolean NOT NULL, `first_name` varchar(50) NOT NULL, `last_name` varchar(50) NOT NULL, `NID` int(10) unsigned UNIQUE NOT NULL, `role` ENUM ('CDU', 'OA', 'CDS', 'SOA', 'CDG', 'CDG-A', 'CDE', 'GV') NOT NULL, `profile_picture` mediumblob, `birthdate` date, `marital_status` ENUM ('Single', 'Married', 'Divorced', 'Widowed', 'Separated', 'In a relationship', 'Engaged', 'Registred partnership'), `haveCar` boolean, `haveCIM` boolean, `haveMessHallCard` boolean, `havePAFCard` boolean, `haveCarCard` boolean, `section` ENUM ('1', '2', '3', 'Commandement', 'Instruction') NOT NULL, `commitment_reasons` varchar(255), `ambitions` varchar(255), `id_phone` bigint unsigned UNIQUE NOT NULL, `id_email_address` bigint unsigned UNIQUE NOT NULL, `password` varchar(64) NOT NULL, `salt` varchar(16) UNIQUE NOT NULL, `private_key` varchar(256) UNIQUE NOT NULL ); CREATE TABLE `phones_number` ( `id` bigint unsigned PRIMARY KEY AUTO_INCREMENT, `phone_number` varchar(30) UNIQUE NOT NULL, `country_code` ENUM('(+93) Afghanistan', '(+355) Albanie', '(+213) Algérie', '(+49) Allemagne', '(+376) Andorre', '(+244) Angola', '(+1 264) Anguilla', '(+1 268) Antigua-et-Barbuda', '(+966) Arabie saoudite', '(+54) Argentine', '(+374) Arménie', '(+297) Aruba', '(+61) Australie', '(+43) Autriche', '(+994) Azerbaïdjan', '(+1 242) Bahamas', '(+973) Bahreïn', '(+880) Bangladesh', '(+1 246) Barbade', '(+375) Bélarus', '(+32) Belgique', '(+501) Belize', '(+229) Bénin', '(+1 441) Bermudes', '(+975) Bhoutan', '(+591) Bolivie', '(+599) Bonaire, Sint Eustatius and Saba', '(+387) Bosnie-Herzégovine', '(+267) Botswana', '(+55) Brésil', '(+673) Brunéi Darussalam', '(+359) Bulgarie', '(+226) Burkina Faso', '(+257) Burundi', '(+238) Cabo Verde', '(+855) Cambodge', '(+237) Cameroun', '(+1) Canada', '(+1 345) Cayman (Iles)', '(+236) Centrafricaine (Rép.)', '(+56) Chili', '(+86) Chine', '(+357) Chypre', '(+57) Colombie', '(+269) Comores', '(+242) Congo (Rép. du)', '(+682) Cook (Iles)', '(+82) Corée (Rép. de)', '(+506) Costa Rica', '(+225) Côte d\'Ivoire', '(+385) Croatie', '(+53) Cuba', '(+599) Curaçao', '(+45) Danemark', '(+246) Diego Garcia', '(+253) Djibouti', '(+1 809, +1 829, +1 849) Dominicaine (Rép.)', '(+1 767) Dominique', '(+20) Egypte', '(+503) El Salvador', '(+971) Emirats arabes unis', '(+593) Equateur', '(+291) Erythrée', '(+34) Espagne', '(+372) Estonie', '(+268) Eswatini', '(+1) Etats-Unis', '(+251) Ethiopie', '(+500) Falkland (Iles) (Malvinas)', '(+7) Fédération de Russie', '(+298) Féroé (Iles)', '(+679) Fidji', '(+358) Finlande', '(+33) France', '(+262) France de l\'océan Indien (La Réunion)', '(+241) Gabon', '(+220) Gambie', '(+995) Géorgie', '(+233) Ghana', '(+350) Gibraltar', '(+30) Grèce', '(+299) Groenland', '(+590) Guadeloupe (Antilles françaises)', '(+1 671) Guam', '(+502) Guatemala', '(+44) Guernesey', '(+224) Guinée', '(+245) Guinée-Bissau', '(+240) Guinée équatoriale', '(+592) Guyana', '(+509) Haïti', '(+504) Honduras', '(+852) Hong Kong', '(+36) Hongrie', '(+91) Inde', '(+62) Indonésie', '(+98) Iran', '(+964) Iraq', '(+353) Irlande', '(+44) Île de Man', '(+354) Islande', '(+972) Israël', '(+39) Italie', '(+1 876) Jamaïque', '(+81) Japon', '(+44) Jersey', '(+962) Jordanie', '(+7) Kazakhstan', '(+254) Kenya', '(+686) Kiribati', '(+965) Koweït', '(+996) Kyrgyzstan', '(+856) Lao', '(+371) Lettonie', '(+961) Liban', '(+266) Lesotho', '(+231) Libéria', '(+218) Libye', '(+423) Liechtenstein', '(+370) Lituanie', '(+352) Luxembourg', '(+853) Macao', '(+261) Madagascar', '(+265) Malawi', '(+60) Malaisie', '(+960) Maldives', '(+223) Mali', '(+356) Malte', '(+692) Marshall (Iles)', '(+596) Martinique (Antilles françaises)', '(+222) Mauritanie', '(+230) Maurice', '(+262) Mayotte', '(+52) Mexique', '(+691) Micronésie', '(+373) Moldova', '(+377) Monaco', '(+976) Mongolie', '(+382) Monténégro', '(+1 664) Montserrat', '(+212) Maroc', '(+258) Mozambique', '(+95) Myanmar', '(+264) Namibie', '(+674) Nauru', '(+31) Pays-Bas', '(+687) Nouvelle-Calédonie', '(+64) Nouvelle-Zélande', '(+505) Nicaragua', '(+227) Niger', '(+234) Nigéria', '(+683) Niue', '(+672) Norfolk (Ile)', '(+47) Norvège', '(+968) Oman', '(+92) Pakistan', '(+680) Palaos', '(+970) Palestine', '(+507) Panama', '(+675) Papouasie-Nouvelle-Guinée', '(+595) Paraguay', '(+51) Pérou', '(+63) Philippines', '(+48) Pologne', '(+689) Polynésie française', '(+351) Portugal', '(+1 787, +1 939) Porto Rico', '(+974) Qatar', '(+383) Kosovo', '(+262) Réunion', '(+40) Roumanie', '(+44) Royaume-Uni', '(+7) Russie', '(+250) Rwanda', '(+1 869) Saint-Christophe-et-Niévès', '(+1 758) Sainte-Lucie', '(+508) Saint-Pierre-et-Miquelon', '(+1 784) Saint-Vincent-et-les-Grenadines', '(+677) Salomon (Iles)', '(+503) Salvador', '(+685) Samoa', '(+378) Saint-Marin', '(+239) Sao Tomé-et-Principe', '(+221) Sénégal', '(+381) Serbie', '(+248) Seychelles', '(+232) Sierra Leone', '(+65) Singapour', '(+1 721) Sint Maarten', '(+421) Slovaquie', '(+386) Slovénie', '(+252) Somalie', '(+249) Soudan', '(+211) Soudan du Sud', '(+94) Sri Lanka', '(+46) Suède', '(+41) Suisse', '(+597) Suriname', '(+47) Svalbard et Jan Mayen (Iles)', '(+963) Syrie', '(+886) Taiwan', '(+992) Tadjikistan', '(+255) Tanzanie', '(+66) Thaïlande', '(+228) Togo', '(+690) Tokelau', '(+676) Tonga', '(+1 868) Trinité-et-Tobago', '(+216) Tunisie', '(+993) Turkménistan', '(+1 649) Turks-et-Caïcos (Iles)', '(+688) Tuvalu', '(+256) Ouganda', '(+380) Ukraine', '(+598) Uruguay', '(+998) Ouzbékistan', '(+678) Vanuatu', '(+379) Vatican', '(+58) Venezuela', '(+84) Vietnam', '(+681) Wallis-et-Futuna', '(+212) Sahara occidental', '(+967) Yémen', '(+260) Zambie', '(+263) Zimbabwe') NOT NULL, `type` ENUM ('mobile', 'landline phone') NOT NULL ); CREATE TABLE `addresses` ( `id` bigint unsigned PRIMARY KEY AUTO_INCREMENT, `street_number` tinyint unsigned NOT NULL, `street_name` varchar(255) NOT NULL, `city` varchar(255) NOT NULL, `postcode` int unsigned NOT NULL, `id_user` bigint unsigned UNIQUE NOT NULL ); CREATE TABLE `email_addresses` ( `id` bigint unsigned PRIMARY KEY AUTO_INCREMENT, `email` varchar(255) ); CREATE TABLE `professions` ( `id` bigint unsigned PRIMARY KEY AUTO_INCREMENT, `profession` varchar(255) NOT NULL, `employer` varchar(255), `wantToBeContacted` boolean NOT NULL, `id_email_address` bigint unsigned UNIQUE, `id_user` bigint unsigned NOT NULL, `id_phone` bigint unsigned ); CREATE TABLE `driving_licence` ( `id` bigint unsigned PRIMARY KEY AUTO_INCREMENT, `licence_type` ENUM ('AM', 'A1', 'A2', 'A', 'B1', 'B', 'C1', 'C', 'D1', 'D', 'BE', 'C1E', 'CE', 'D1E', 'DE') NOT NULL, `id_user` bigint unsigned NOT NULL ); CREATE TABLE `tokens` ( `id` bigint unsigned PRIMARY KEY AUTO_INCREMENT, `sign` varchar(255) UNIQUE NOT NULL, `expiration_date` timestamp, `id_user` bigint unsigned NOT NULL ); CREATE TABLE `military_driving_licence` ( `id` bigint unsigned PRIMARY KEY AUTO_INCREMENT, `military_licence_type` ENUM ('MOTO 125', 'MOTO', 'VL', 'PL', 'SPL', 'TC') NOT NULL, `id_user` bigint unsigned NOT NULL ); CREATE TABLE `military_diplomas` ( `id` bigint unsigned PRIMARY KEY AUTO_INCREMENT, `diploma_name` varchar(50) NOT NULL, `issued_date` date, `id_user` bigint unsigned NOT NULL ); CREATE TABLE `moal` ( `id` bigint unsigned PRIMARY KEY AUTO_INCREMENT, `moal_name` varchar(50) NOT NULL, `id_user` bigint unsigned NOT NULL ); CREATE TABLE `pages` ( `id` bigint unsigned PRIMARY KEY AUTO_INCREMENT, `content` varchar(255) NOT NULL ); CREATE TABLE `courses` ( `id` bigint unsigned PRIMARY KEY AUTO_INCREMENT, `theme` varchar(20) NOT NULL, `title` varchar(50) UNIQUE NOT NULL, `id_page` bigint unsigned NOT NULL, `read_time` time(0) NOT NULL, `id_target` bigint unsigned NOT NULL, `id_first_author` bigint unsigned NOT NULL ); CREATE TABLE `first_authors` ( `id` bigint unsigned PRIMARY KEY AUTO_INCREMENT, `release_date` date NOT NULL, `id_user` bigint unsigned NOT NULL ); CREATE TABLE `writers` ( `id` bigint unsigned PRIMARY KEY AUTO_INCREMENT, `modification_date` date NOT NULL, `course_id` bigint unsigned NOT NULL, `writer_id` bigint unsigned NOT NULL ); CREATE TABLE `targets` ( `id` bigint unsigned PRIMARY KEY AUTO_INCREMENT, `target_name` ENUM ('Capitaine', 'Lieutenant', 'Sous-Lieutenant', 'Aspirant', 'Major', 'Adjudant-Chef', 'Adjudant', 'Sergent-Chef BM2', 'Sergent-Chef', 'Sergent', 'Caporal-Chef de première classe', 'Caporal-Chef', 'Caporal', 'Première classe', 'Marsouin') NOT NULL ); CREATE TABLE `journeys` ( `id` bigint unsigned PRIMARY KEY AUTO_INCREMENT, `theme` varchar(20) NOT NULL, `id_target` bigint unsigned NOT NULL, `id_course` bigint unsigned NOT NULL ); ALTER TABLE `phones_number` ADD FOREIGN KEY (`id`) REFERENCES `users` (`id_phone`); ALTER TABLE `email_addresses` ADD FOREIGN KEY (`id`) REFERENCES `users` (`id_email_address`); ALTER TABLE `addresses` ADD FOREIGN KEY (`id_user`) REFERENCES `users` (`id`); ALTER TABLE `professions` ADD FOREIGN KEY (`id_email_address`) REFERENCES `email_addresses` (`id`); ALTER TABLE `professions` ADD FOREIGN KEY (`id_user`) REFERENCES `users` (`id`); ALTER TABLE `professions` ADD FOREIGN KEY (`id_phone`) REFERENCES `phones_number` (`id`); ALTER TABLE `driving_licence` ADD FOREIGN KEY (`id_user`) REFERENCES `users` (`id`); ALTER TABLE `tokens` ADD FOREIGN KEY (`id_user`) REFERENCES `users` (`id`); ALTER TABLE `military_driving_licence` ADD FOREIGN KEY (`id_user`) REFERENCES `users` (`id`); ALTER TABLE `military_diplomas` ADD FOREIGN KEY (`id_user`) REFERENCES `users` (`id`); ALTER TABLE `moal` ADD FOREIGN KEY (`id_user`) REFERENCES `users` (`id`); ALTER TABLE `pages` ADD FOREIGN KEY (`id`) REFERENCES `courses` (`id_page`); ALTER TABLE `targets` ADD FOREIGN KEY (`id`) REFERENCES `courses` (`id_target`); ALTER TABLE `courses` ADD FOREIGN KEY (`id_first_author`) REFERENCES `first_authors` (`id`); ALTER TABLE `first_authors` ADD FOREIGN KEY (`id_user`) REFERENCES `users` (`id`); ALTER TABLE `courses` ADD FOREIGN KEY (`id`) REFERENCES `writers` (`course_id`); ALTER TABLE `writers` ADD FOREIGN KEY (`writer_id`) REFERENCES `users` (`id`); ALTER TABLE `journeys` ADD FOREIGN KEY (`id_target`) REFERENCES `targets` (`id`); ALTER TABLE `courses` ADD FOREIGN KEY (`id`) REFERENCES `journeys` (`id_course`);
Write, Run & Share MySQL queries online using OneCompiler's MySQL online editor and compiler for free. It's one of the robust, feature-rich online editor and compiler for MySQL. Getting started with the OneCompiler's MySQL editor is really simple and pretty fast. The editor shows sample boilerplate code when you choose language as 'MySQL' and start writing queries to learn and test online without worrying about tedious process of installation.
MySQL is a open-source, free and very popular relational database management system which is developed, distributed and supported by Oracle corporation.
CREATE TABLE table_name (
column1 datatype,
column2 datatype,
....);
CREATE TABLE EMPLOYEE (
empId INTEGER PRIMARY KEY,
name TEXT NOT NULL,
dept TEXT NOT NULL
);
ALTER TABLE Table_name ADD column_name datatype;
INSERT INTO EMPLOYEE VALUES (0001, 'Dave', 'Sales');
TRUNCATE table table_name;
DROP TABLE table_name;
RENAME TABLE table_name1 to new_table_name1;
--Line1;
/* Line1,
Line2 */
INSERT INTO table_name (column1, column2, column3, ...) VALUES (value1, value2, value3, ...);
Note: Column names are optional.
INSERT INTO EMPLOYEE VALUES (0001, 'Ava', 'Sales');
SELECT column1, column2, ...
FROM table_name
[where condition];
SELECT * FROM EMPLOYEE where dept ='sales';
UPDATE table_name
SET column1 = value1, column2 = value2, ...
WHERE condition;
UPDATE EMPLOYEE SET dept = 'Sales' WHERE empId='0001';
DELETE FROM table_name where condition;
DELETE from EMPLOYEE where empId='0001';
CREATE INDEX index_name on table_name(column_name);
CREATE UNIQUE INDEX index_name on table_name(column_name);
DROP INDEX index_name ON table_name;
Creating a View:
CREATE VIEW View_name AS
Query;
SELECT * FROM View_name;
ALTER View View_name AS
Query;
DROP VIEW View_name;
CREATE TRIGGER trigger_name trigger_time trigger_event
ON tbl_name FOR EACH ROW [trigger_order] trigger_body
/* where
trigger_time: { BEFORE | AFTER }
trigger_event: { INSERT | UPDATE | DELETE }
trigger_order: { FOLLOWS | PRECEDES } */
DROP TRIGGER [IF EXISTS] trigger_name;
CREATE PROCEDURE sp_name(p1 datatype)
BEGIN
/*Stored procedure code*/
END;
CALL sp_name;
DROP PROCEDURE sp_name;
SELECT * FROM TABLE1 INNER JOIN TABLE2 where condition;
SELECT * FROM TABLE1 LEFT JOIN TABLE2 ON condition;
SELECT * FROM TABLE1 RIGHT JOIN TABLE2 ON condition;
SELECT select_list from TABLE1 CROSS JOIN TABLE2;