2021-06-18 13:29:25 +02:00
|
|
|
CREATE DATABASE IF NOT EXISTS main;
|
|
|
|
USE main;
|
|
|
|
CREATE TABLE Persons (
|
2021-07-05 19:11:23 +02:00
|
|
|
PersonID int NOT NULL AUTO_INCREMENT,
|
2021-07-12 11:51:30 +02:00
|
|
|
CreatedAt datetime,
|
2023-04-14 18:56:17 +02:00
|
|
|
Age float DEFAULT 20 NOT NULL,
|
2021-06-18 13:29:25 +02:00
|
|
|
LastName varchar(255),
|
|
|
|
FirstName varchar(255),
|
|
|
|
Address varchar(255),
|
2021-07-05 19:11:23 +02:00
|
|
|
City varchar(255),
|
|
|
|
PRIMARY KEY (PersonID)
|
2021-06-18 13:29:25 +02:00
|
|
|
);
|
2024-03-04 17:55:10 +01:00
|
|
|
CREATE TABLE Person (
|
|
|
|
PersonID int NOT NULL AUTO_INCREMENT,
|
|
|
|
Name varchar(255),
|
|
|
|
PRIMARY KEY (PersonID)
|
|
|
|
);
|
2021-07-05 19:11:23 +02:00
|
|
|
CREATE TABLE Tasks (
|
|
|
|
TaskID int NOT NULL AUTO_INCREMENT,
|
|
|
|
PersonID INT,
|
|
|
|
TaskName varchar(255),
|
2022-04-01 18:13:28 +02:00
|
|
|
CreatedAt DATE,
|
2021-07-05 19:11:23 +02:00
|
|
|
PRIMARY KEY (TaskID),
|
|
|
|
CONSTRAINT fkPersons
|
|
|
|
FOREIGN KEY(PersonID)
|
|
|
|
REFERENCES Persons(PersonID)
|
|
|
|
);
|
2022-02-08 17:15:08 +01:00
|
|
|
CREATE TABLE Products (
|
|
|
|
id serial primary key,
|
|
|
|
name text,
|
|
|
|
updated time
|
|
|
|
);
|
2024-12-17 16:23:24 +01:00
|
|
|
CREATE TABLE `table with space` (
|
|
|
|
id serial primary key,
|
|
|
|
name text
|
|
|
|
);
|
2021-07-12 12:10:11 +02:00
|
|
|
INSERT INTO Persons (FirstName, LastName, Age, Address, City, CreatedAt) VALUES ('Mike', 'Hughes', 28.2, '123 Fake Street', 'Belfast', '2021-01-19 03:14:07');
|
2022-04-14 14:06:22 +02:00
|
|
|
INSERT INTO Persons (FirstName, LastName, Age, Address, City, CreatedAt) VALUES ('Dave', 'Johnson', 29, '124 Fake Street', 'Belfast', '2022-04-01 00:11:11');
|
2024-03-04 17:55:10 +01:00
|
|
|
INSERT INTO Person (Name) VALUES ('Elf');
|
2022-04-01 18:13:28 +02:00
|
|
|
INSERT INTO Tasks (PersonID, TaskName, CreatedAt) VALUES (1, 'assembling', '2020-01-01');
|
|
|
|
INSERT INTO Tasks (PersonID, TaskName, CreatedAt) VALUES (2, 'processing', '2019-12-31');
|
2022-02-08 17:15:08 +01:00
|
|
|
INSERT INTO Products (name, updated) VALUES ('Meat', '11:00:22'), ('Fruit', '10:00:00');
|