2021-06-18 16:03:22 +02:00
|
|
|
SELECT 'CREATE DATABASE main'
|
|
|
|
WHERE NOT EXISTS (SELECT FROM pg_database WHERE datname = 'main')\gexec
|
2022-03-04 16:50:19 +01:00
|
|
|
CREATE SCHEMA test;
|
2022-02-25 12:39:46 +01:00
|
|
|
CREATE TYPE person_job AS ENUM ('qa', 'programmer', 'designer');
|
2021-06-18 16:03:22 +02:00
|
|
|
CREATE TABLE Persons (
|
2021-07-05 19:11:23 +02:00
|
|
|
PersonID SERIAL PRIMARY KEY,
|
2021-06-18 16:03:22 +02:00
|
|
|
LastName varchar(255),
|
|
|
|
FirstName varchar(255),
|
|
|
|
Address varchar(255),
|
2022-02-25 12:39:46 +01:00
|
|
|
City varchar(255) DEFAULT 'Belfast',
|
|
|
|
Type person_job
|
2021-06-18 16:03:22 +02:00
|
|
|
);
|
2021-06-23 13:44:54 +02:00
|
|
|
CREATE TABLE Tasks (
|
2021-07-05 19:11:23 +02:00
|
|
|
TaskID SERIAL PRIMARY KEY,
|
2022-02-02 19:15:17 +01:00
|
|
|
ExecutorID INT,
|
|
|
|
QaID INT,
|
2021-08-05 10:59:08 +02:00
|
|
|
Completed BOOLEAN,
|
2021-06-23 13:44:54 +02:00
|
|
|
TaskName varchar(255),
|
2022-02-02 19:15:17 +01:00
|
|
|
CONSTRAINT fkexecutor
|
|
|
|
FOREIGN KEY(ExecutorID)
|
|
|
|
REFERENCES Persons(PersonID),
|
|
|
|
CONSTRAINT fkqa
|
|
|
|
FOREIGN KEY(QaID)
|
|
|
|
REFERENCES Persons(PersonID)
|
2021-06-23 13:44:54 +02:00
|
|
|
);
|
2021-06-28 13:36:05 +02:00
|
|
|
CREATE TABLE Products (
|
2021-07-05 19:11:23 +02:00
|
|
|
ProductID SERIAL PRIMARY KEY,
|
2021-06-28 13:36:05 +02:00
|
|
|
ProductName varchar(255)
|
|
|
|
);
|
|
|
|
CREATE TABLE Products_Tasks (
|
|
|
|
ProductID INT NOT NULL,
|
|
|
|
TaskID INT NOT NULL,
|
|
|
|
CONSTRAINT fkProducts
|
|
|
|
FOREIGN KEY(ProductID)
|
2021-08-05 10:59:08 +02:00
|
|
|
REFERENCES Products(ProductID),
|
2021-06-28 13:36:05 +02:00
|
|
|
CONSTRAINT fkTasks
|
|
|
|
FOREIGN KEY(TaskID)
|
2021-08-05 10:59:08 +02:00
|
|
|
REFERENCES Tasks(TaskID),
|
2021-06-28 13:36:05 +02:00
|
|
|
PRIMARY KEY (ProductID, TaskID)
|
|
|
|
);
|
2022-03-04 16:50:19 +01:00
|
|
|
CREATE TABLE test.table1 (
|
|
|
|
id SERIAL PRIMARY KEY,
|
|
|
|
Name varchar(255)
|
|
|
|
);
|
2022-02-25 12:39:46 +01:00
|
|
|
INSERT INTO Persons (FirstName, LastName, Address, City, Type) VALUES ('Mike', 'Hughes', '123 Fake Street', 'Belfast', 'qa');
|
|
|
|
INSERT INTO Persons (FirstName, LastName, Address, City, Type) VALUES ('John', 'Smith', '64 Updown Road', 'Dublin', 'programmer');
|
2022-02-02 19:15:17 +01:00
|
|
|
INSERT INTO Tasks (ExecutorID, QaID, TaskName, Completed) VALUES (1, 2, 'assembling', TRUE);
|
|
|
|
INSERT INTO Tasks (ExecutorID, QaID, TaskName, Completed) VALUES (2, 1, 'processing', FALSE);
|
2021-07-05 19:11:23 +02:00
|
|
|
INSERT INTO Products (ProductName) VALUES ('Computers');
|
|
|
|
INSERT INTO Products (ProductName) VALUES ('Laptops');
|
|
|
|
INSERT INTO Products (ProductName) VALUES ('Chairs');
|
2021-06-28 13:36:05 +02:00
|
|
|
INSERT INTO Products_Tasks (ProductID, TaskID) VALUES (1, 1);
|
|
|
|
INSERT INTO Products_Tasks (ProductID, TaskID) VALUES (2, 1);
|
|
|
|
INSERT INTO Products_Tasks (ProductID, TaskID) VALUES (3, 1);
|
2021-06-29 18:42:46 +02:00
|
|
|
INSERT INTO Products_Tasks (ProductID, TaskID) VALUES (1, 2);
|
2022-03-04 16:50:19 +01:00
|
|
|
INSERT INTO test.table1 (Name) VALUES ('Test');
|