|
|
|
CREATE DATABASE [CompaniesDB];
|
|
|
|
GO
|
|
|
|
|
|
|
|
USE [CompaniesDB];
|
|
|
|
GO
|
|
|
|
|
|
|
|
CREATE TABLE [Companies] (
|
|
|
|
[CompanyId] int NOT NULL IDENTITY,
|
|
|
|
[Name] nvarchar(max) NOT NULL,
|
|
|
|
[ContractStatus] int NOT NULL CHECK ([ContractStatus] IN(0, 1, 2)),
|
|
|
|
CONSTRAINT [PK_CompanyId] PRIMARY KEY ([CompanyId])
|
|
|
|
);
|
|
|
|
GO
|
|
|
|
|
|
|
|
CREATE TABLE [Users] (
|
|
|
|
[UserId] int NOT NULL IDENTITY,
|
|
|
|
[CompanyID] int NOT NULL,
|
|
|
|
[Name] nvarchar(max) NOT NULL,
|
|
|
|
[Login] nvarchar(max) NOT NULL,
|
|
|
|
[Password] nvarchar(max) NOT NULL,
|
|
|
|
CONSTRAINT [PK_UserId] PRIMARY KEY ([UserId]),
|
|
|
|
CONSTRAINT [FK_Users_Companies] FOREIGN KEY (CompanyID) REFERENCES [Companies] (CompanyId) ON DELETE CASCADE
|
|
|
|
);
|
|
|
|
GO
|
|
|
|
|
|
|
|
INSERT INTO [Companies] (Name, ContractStatus) VALUES
|
|
|
|
('Defend Studio', '0'),
|
|
|
|
('Yandex Music', '1')
|
|
|
|
GO
|