2021-10-27 18:32:02 +02:00
|
|
|
USE master;
|
2022-03-04 16:12:07 +01:00
|
|
|
|
|
|
|
IF NOT EXISTS(SELECT 1 FROM sys.schemas WHERE name = 'Chains')
|
|
|
|
BEGIN
|
|
|
|
EXEC sys.sp_executesql N'CREATE SCHEMA Chains;'
|
|
|
|
END
|
|
|
|
|
2021-10-27 18:32:02 +02:00
|
|
|
IF OBJECT_ID ('dbo.products', 'U') IS NOT NULL
|
|
|
|
DROP TABLE products;
|
|
|
|
GO
|
|
|
|
CREATE TABLE products
|
|
|
|
(
|
|
|
|
id int IDENTITY(1,1),
|
2022-12-02 17:17:56 +01:00
|
|
|
name varchar (20) NOT NULL,
|
2021-11-05 13:33:48 +01:00
|
|
|
description varchar(30),
|
|
|
|
CONSTRAINT pk_products PRIMARY KEY NONCLUSTERED (id)
|
2021-10-27 18:32:02 +02:00
|
|
|
);
|
2021-11-05 13:33:48 +01:00
|
|
|
|
2021-10-27 18:32:02 +02:00
|
|
|
IF OBJECT_ID ('dbo.tasks', 'U') IS NOT NULL
|
|
|
|
DROP TABLE tasks;
|
|
|
|
GO
|
|
|
|
CREATE TABLE tasks
|
|
|
|
(
|
|
|
|
taskid int IDENTITY(1,1),
|
2022-12-02 17:17:56 +01:00
|
|
|
taskname varchar (20) NOT NULL,
|
2021-11-05 13:33:48 +01:00
|
|
|
productid int,
|
|
|
|
CONSTRAINT pk_tasks PRIMARY KEY NONCLUSTERED (taskid),
|
|
|
|
CONSTRAINT fk_products FOREIGN KEY (productid) REFERENCES products (id),
|
|
|
|
);
|
|
|
|
|
|
|
|
IF OBJECT_ID ('dbo.people', 'U') IS NOT NULL
|
|
|
|
DROP TABLE people;
|
|
|
|
GO
|
|
|
|
CREATE TABLE people
|
|
|
|
(
|
2022-12-02 17:17:56 +01:00
|
|
|
name varchar(30) NOT NULL,
|
2023-04-14 19:10:10 +02:00
|
|
|
age int default 20 NOT NULL,
|
2021-11-05 13:33:48 +01:00
|
|
|
CONSTRAINT pk_people PRIMARY KEY NONCLUSTERED (name, age)
|
2021-10-27 18:32:02 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
INSERT products
|
|
|
|
(name, description)
|
|
|
|
VALUES
|
2022-02-08 17:15:08 +01:00
|
|
|
('Bananas', 'Fruit thing'),
|
2021-10-27 18:32:02 +02:00
|
|
|
('Meat', 'Animal thing');
|
2022-02-08 17:15:08 +01:00
|
|
|
|
2021-10-27 18:32:02 +02:00
|
|
|
INSERT tasks
|
2021-11-05 13:33:48 +01:00
|
|
|
(taskname, productid)
|
|
|
|
VALUES
|
|
|
|
('Processing', 1);
|
|
|
|
|
2022-02-04 17:17:36 +01:00
|
|
|
INSERT INTO people (name, age)
|
2023-04-14 19:10:10 +02:00
|
|
|
VALUES ('Bob', 30),
|
|
|
|
('Bert', 10),
|
|
|
|
('Jack', 12),
|
|
|
|
('Mike', 31),
|
|
|
|
('Dave', 44),
|
|
|
|
('Jim', 43),
|
|
|
|
('Kerry', 32),
|
|
|
|
('Julie', 12),
|
|
|
|
('Kim', 55),
|
|
|
|
('Andy', 33),
|
|
|
|
('John', 22),
|
|
|
|
('Ruth', 66),
|
|
|
|
('Robert', 88),
|
|
|
|
('Bobert', 99),
|
|
|
|
('Jan', 22),
|
|
|
|
('Megan', 11);
|
2022-03-04 16:12:07 +01:00
|
|
|
|
|
|
|
|
|
|
|
IF OBJECT_ID ('Chains.sizes', 'U') IS NOT NULL
|
|
|
|
DROP TABLE Chains.sizes;
|
|
|
|
GO
|
|
|
|
CREATE TABLE Chains.sizes
|
|
|
|
(
|
|
|
|
sizeid int IDENTITY(1, 1),
|
|
|
|
name varchar(30),
|
|
|
|
CONSTRAINT pk_size PRIMARY KEY NONCLUSTERED (sizeid)
|
|
|
|
);
|
|
|
|
|