USE dbi509645
GO

CREATE TABLE UserRole (
	ID INT PRIMARY KEY IDENTITY(0,1) NOT NULL,
	[Role] NVARCHAR(255)
)
GO

CREATE TABLE Users (
	ID INT PRIMARY KEY IDENTITY NOT NULL,
	[Name] NVARCHAR(255) NOT NULL,
	[Password] NVARCHAR(4000) NOT NULL,
	[Role] INT FOREIGN KEY REFERENCES UserRole(ID) NOT NULL
)
GO

CREATE TABLE ContactForm (
	ID INT PRIMARY KEY IDENTITY NOT NULL,
	[Name] NVARCHAR(255) NOT NULL,
	Email NVARCHAR(255) NOT NULL
)
GO

CREATE TABLE Announcements (
	ID INT PRIMARY KEY IDENTITY NOT NULL,
	[Author] INT FOREIGN KEY REFERENCES Users(ID) NOT NULL,
	[Description] NVARCHAR(MAX),
	[Title] NVARCHAR(255) NOT NULL,
	[PublishDate] DATETIME NOT NULL,
	[IsImportant] BIT NOT NULL,
	[IsSticky] BIT NOT NULL,
)
GO

CREATE TABLE Comments (
	ID INT PRIMARY KEY IDENTITY NOT NULL,
	[Author] INT FOREIGN KEY REFERENCES Users(ID) NOT NULL,
	[Description] NVARCHAR(MAX) NOT NULL,
	[Title] NVARCHAR(255) NOT NULL,
	[PublishDate] DATETIME NOT NULL
)
GO

CREATE TABLE AnnouncementsComments (
	AnnouncementID INT FOREIGN KEY REFERENCES Announcements(ID) NOT NULL,
	CommentID INT FOREIGN KEY REFERENCES Comments(ID) NOT NULL
)
GO

CREATE TABLE CommentsResponses (
	CommentID INT FOREIGN KEY REFERENCES Comments(ID) NOT NULL,
	ResponseID INT FOREIGN KEY REFERENCES Comments(ID) NOT NULL
)
GO