2021-06-18 16:03:22 +02:00
|
|
|
SELECT 'CREATE DATABASE main'
|
|
|
|
WHERE NOT EXISTS (SELECT FROM pg_database WHERE datname = 'main')\gexec
|
2023-08-01 19:18:53 +02:00
|
|
|
CREATE SCHEMA "test-1";
|
2023-09-12 14:54:39 +02:00
|
|
|
CREATE TYPE person_job AS ENUM ('qa', 'programmer', 'designer', 'support');
|
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',
|
2023-04-14 18:56:17 +02:00
|
|
|
Age INTEGER DEFAULT 20 NOT NULL,
|
2022-02-25 12:39:46 +01:00
|
|
|
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)
|
|
|
|
);
|
2023-08-01 19:18:53 +02:00
|
|
|
CREATE TABLE "test-1".table1 (
|
2022-03-04 16:50:19 +01:00
|
|
|
id SERIAL PRIMARY KEY,
|
|
|
|
Name varchar(255)
|
|
|
|
);
|
2023-07-26 13:31:46 +02:00
|
|
|
CREATE TABLE CompositeTable (
|
|
|
|
KeyPartOne varchar(128),
|
|
|
|
KeyPartTwo varchar(128),
|
|
|
|
Name varchar(255),
|
|
|
|
PRIMARY KEY (KeyPartOne, KeyPartTwo)
|
|
|
|
);
|
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');
|
2023-09-12 14:54:39 +02:00
|
|
|
INSERT INTO Persons (FirstName, LastName, Address, City, Type, Age) VALUES ('Foo', 'Bar', 'Foo Street', 'Bartown', 'support', 0);
|
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);
|
2023-08-01 19:18:53 +02:00
|
|
|
INSERT INTO "test-1".table1 (Name) VALUES ('Test');
|
2023-07-26 13:31:46 +02:00
|
|
|
INSERT INTO CompositeTable (KeyPartOne, KeyPartTwo, Name) VALUES ('aaa', 'bbb', 'Michael');
|
|
|
|
INSERT INTO CompositeTable (KeyPartOne, KeyPartTwo, Name) VALUES ('bbb', 'ccc', 'Andrew');
|
|
|
|
INSERT INTO CompositeTable (KeyPartOne, KeyPartTwo, Name) VALUES ('ddd', '', 'OneKey');
|