CREATE TABLE RoleT (
    RoleIdentifier INT PRIMARY KEY,
    RoleName NVARCHAR(50) NOT NULL
);

CREATE TABLE UsersT (
    UserID INT PRIMARY KEY,
    RoleIdentifier INT,
    UserName NVARCHAR(50) NOT NULL,
    Password NVARCHAR(255) NOT NULL,
    FOREIGN KEY (RoleIdentifier) REFERENCES RoleT(RoleIdentifier)
);

CREATE TABLE PrivilegesT (
    PrivilegesID INT PRIMARY KEY,
    RoleIdentifier INT,
    PrivilegeName NVARCHAR(200) NOT NULL,
    FOREIGN KEY (RoleIdentifier) REFERENCES RoleT(RoleIdentifier)
);


CREATE TABLE Products (
    ProductID INT PRIMARY KEY,
    ProductName NVARCHAR(50) NOT NULL,
    Quantity INT NOT NULL,
    Location NVARCHAR(50) NOT NULL
);

CREATE TABLE Orders (
    OrderID INT PRIMARY KEY,
    UserID INT,
    OrderDate DATE NOT NULL,
    Status NVARCHAR(20) NOT NULL,
    FOREIGN KEY (UserID) REFERENCES UsersT(UserID)
);

CREATE TABLE OrderItems (
    OrderItemsID INT PRIMARY KEY,
    OrderID INT,
    ProductID INT,
    Quantity INT NOT NULL,
    FOREIGN KEY (OrderID) REFERENCES Orders(OrderID),
    FOREIGN KEY (ProductID) REFERENCES Products(ProductID)
);

INSERT INTO RoleT (RoleIdentifier, RoleName) VALUES (1, 'Admin');
INSERT INTO RoleT (RoleIdentifier, RoleName) VALUES (2, 'User');
INSERT INTO RoleT (RoleIdentifier, RoleName) VALUES (3, 'Manager');
INSERT INTO RoleT (RoleIdentifier, RoleName) VALUES (4, 'Guest');
INSERT INTO RoleT (RoleIdentifier, RoleName) VALUES (5, 'Support');

INSERT INTO UsersT (UserID, RoleIdentifier, UserName, Password) VALUES (1, 1, 'admin', 'adminpass');
INSERT INTO UsersT (UserID, RoleIdentifier, UserName, Password) VALUES (2, 2, 'john_doe', 'password123');
INSERT INTO UsersT (UserID, RoleIdentifier, UserName, Password) VALUES (3, 3, 'alice', 'alicepass');
INSERT INTO UsersT (UserID, RoleIdentifier, UserName, Password) VALUES (4, 4, 'guest_user', 'guestpass');
INSERT INTO UsersT (UserID, RoleIdentifier, UserName, Password) VALUES (5, 5, 'support_guy', 'supportpass');

INSERT INTO PrivilegesT (PrivilegesID, RoleIdentifier, PrivilegeName) VALUES (1, 1, 'Full Control');
INSERT INTO PrivilegesT (PrivilegesID, RoleIdentifier, PrivilegeName) VALUES (2, 2, 'Read Only');
INSERT INTO PrivilegesT (PrivilegesID, RoleIdentifier, PrivilegeName) VALUES (3, 3, 'Edit Content');
INSERT INTO PrivilegesT (PrivilegesID, RoleIdentifier, PrivilegeName) VALUES (4, 4, 'View Content');
INSERT INTO PrivilegesT (PrivilegesID, RoleIdentifier, PrivilegeName) VALUES (5, 5, 'Technical Support');

INSERT INTO Products (ProductID, ProductName, Quantity, Location) VALUES (1, 'Laptop', 50, 'Warehouse A');
INSERT INTO Products (ProductID, ProductName, Quantity, Location) VALUES (2, 'Mouse', 150, 'Warehouse B');
INSERT INTO Products (ProductID, ProductName, Quantity, Location) VALUES (3, 'Keyboard', 100, 'Warehouse A');
INSERT INTO Products (ProductID, ProductName, Quantity, Location) VALUES (4, 'Monitor', 75, 'Warehouse C');
INSERT INTO Products (ProductID, ProductName, Quantity, Location) VALUES (5, 'Printer', 60, 'Warehouse B');

INSERT INTO Orders (OrderID, UserID, OrderDate, Status) VALUES (1, 1, '2023-01-10', 'Completed');
INSERT INTO Orders (OrderID, UserID, OrderDate, Status) VALUES (2, 2, '2023-02-15', 'Pending');
INSERT INTO Orders (OrderID, UserID, OrderDate, Status) VALUES (3, 3, '2023-03-20', 'Shipped');
INSERT INTO Orders (OrderID, UserID, OrderDate, Status) VALUES (4, 4, '2023-04-25', 'Delivered');
INSERT INTO Orders (OrderID, UserID, OrderDate, Status) VALUES (5, 5, '2023-05-30', 'Canceled');

INSERT INTO OrderItems (OrderItemsID, OrderID, ProductID, Quantity) VALUES (1, 1, 1, 2);
INSERT INTO OrderItems (OrderItemsID, OrderID, ProductID, Quantity) VALUES (2, 2, 2, 5);
INSERT INTO OrderItems (OrderItemsID, OrderID, ProductID, Quantity) VALUES (3, 3, 3, 1);
INSERT INTO OrderItems (OrderItemsID, OrderID, ProductID, Quantity) VALUES (4, 4, 4, 3);
INSERT INTO OrderItems (OrderItemsID, OrderID, ProductID, Quantity) VALUES (5, 5, 5, 4);

Select * from UsersT; 1.	Создать необходимые объекты (представления, индексы, последовательности и пр.) для базы данных для СУБД SQL Server, продемонстрировать их работу