
How to Master the Basics of Any Topic
Guest 7 3rd Mar, 2025
USE [DormitoryManagement]
GO
/****** Object: Table [dbo].[Account] Script Date: 3/23/2021 4:56:36 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Account](
[id] [int] IDENTITY(1,1) NOT NULL,
[username] [nvarchar](255) NULL,
[password] [nvarchar](255) NULL,
[isManager] [bit] NULL,
[isActive] [bit] NULL,
CONSTRAINT [PK_Account] PRIMARY KEY CLUSTERED
(
[id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object: Table [dbo].[Bed] Script Date: 3/23/2021 4:56:36 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Bed](
[id] [int] IDENTITY(1,1) NOT NULL,
[room_id] [int] NULL,
[bedNumber] [tinyint] NULL,
[isAvailable] [bit] NULL,
CONSTRAINT [PK_Bed] PRIMARY KEY CLUSTERED
(
[id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object: Table [dbo].[Dom] Script Date: 3/23/2021 4:56:36 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Dom](
[id] [int] IDENTITY(1,1) NOT NULL,
[name] [nvarchar](1) NULL,
CONSTRAINT [PK_Dom] PRIMARY KEY CLUSTERED
(
[id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object: Table [dbo].[Floor] Script Date: 3/23/2021 4:56:36 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Floor](
[id] [int] IDENTITY(1,1) NOT NULL,
[dom_id] [int] NULL,
[number] [int] NULL,
CONSTRAINT [PK_Floor] PRIMARY KEY CLUSTERED
(
[id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object: Table [dbo].[Invoice] Script Date: 3/23/2021 4:56:36 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Invoice](
[id] [int] IDENTITY(1,1) NOT NULL,
[student_id] [int] NULL,
[type_id] [int] NULL,
[amount] [float] NULL,
[numberOfUses] [int] NULL,
[note] [nvarchar](max) NULL,
[isPaid] [bit] NULL,
[deadline] [datetime] NULL,
[dateCreated] [datetime] NULL,
CONSTRAINT [PK_Bill] PRIMARY KEY CLUSTERED
(
[id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
/****** Object: Table [dbo].[Invoice Type] Script Date: 3/23/2021 4:56:36 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Invoice Type](
[id] [int] IDENTITY(1,1) NOT NULL,
[name] [nvarchar](255) NULL,
CONSTRAINT [PK_Bill Type] PRIMARY KEY CLUSTERED
(
[id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object: Table [dbo].[Price] Script Date: 3/23/2021 4:56:36 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Price](
[id] [int] IDENTITY(1,1) NOT NULL,
[price_type] [int] NULL,
[standard_price] [money] NULL,
[standard_usage] [int] NULL,
[date] [datetime] NULL,
CONSTRAINT [PK_Price] PRIMARY KEY CLUSTERED
(
[id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object: Table [dbo].[Price Type] Script Date: 3/23/2021 4:56:36 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Price Type](
[id] [int] NOT NULL,
[name] [nvarchar](255) NULL,
CONSTRAINT [PK_Price Type] PRIMARY KEY CLUSTERED
(
[id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object: Table [dbo].[Request] Script Date: 3/23/2021 4:56:36 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Request](
[id] [int] IDENTITY(1,1) NOT NULL,
[student_id] [int] NULL,
[type_id] [int] NULL,
[title] [nvarchar](255) NULL,
[content] [nvarchar](max) NULL,
[reply] [nvarchar](max) NULL,
[isDone] [bit] NULL,
[dateCreated] [datetime] NULL,
CONSTRAINT [PK_Request] PRIMARY KEY CLUSTERED
(
[id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
/****** Object: Table [dbo].[Request Type] Script Date: 3/23/2021 4:56:36 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Request Type](
[id] [int] IDENTITY(1,1) NOT NULL,
[name] [nvarchar](255) NULL,
CONSTRAINT [PK_Request Type] PRIMARY KEY CLUSTERED
(
[id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object: Table [dbo].[Room] Script Date: 3/23/2021 4:56:36 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Room](
[id] [int] IDENTITY(1,1) NOT NULL,
[floor_id] [int] NULL,
[roomNumber] [nvarchar](5) NULL,
[roomGender] [bit] NULL,
CONSTRAINT [PK_Room] PRIMARY KEY CLUSTERED
(
[id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object: Table [dbo].[Room Usage] Script Date: 3/23/2021 4:56:36 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Room Usage](
[id] [int] IDENTITY(1,1) NOT NULL,
[room_id] [int] NULL,
[water_usage] [int] NULL,
[electric_usage] [int] NULL,
[date] [datetime] NULL,
CONSTRAINT [PK_Room Usage] PRIMARY KEY CLUSTERED
(
[id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object: Table [dbo].[Student] Script Date: 3/23/2021 4:56:36 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Student](
[id] [int] IDENTITY(1,1) NOT NULL,
[bed_id] [int] NULL,
[name] [nvarchar](255) NULL,
[studentCode] [nvarchar](8) NULL,
[gender] [bit] NULL,
[email] [nvarchar](255) NULL,
[avatar] [nvarchar](max) NULL,
[hasInDorm] [bit] NULL,
CONSTRAINT [PK_Student] PRIMARY KEY CLUSTERED
(
[id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
ALTER TABLE [dbo].[Invoice] ADD CONSTRAINT [DF_Bill_dateCreated] DEFAULT (getdate()) FOR [dateCreated]
GO
ALTER TABLE [dbo].[Bed] WITH CHECK ADD CONSTRAINT [FK_Bed_Room] FOREIGN KEY([room_id])
REFERENCES [dbo].[Room] ([id])
GO
ALTER TABLE [dbo].[Bed] CHECK CONSTRAINT [FK_Bed_Room]
GO
ALTER TABLE [dbo].[Floor] WITH CHECK ADD CONSTRAINT [FK_Floor_Dom] FOREIGN KEY([dom_id])
REFERENCES [dbo].[Dom] ([id])
GO
ALTER TABLE [dbo].[Floor] CHECK CONSTRAINT [FK_Floor_Dom]
GO
ALTER TABLE [dbo].[Invoice] WITH CHECK ADD CONSTRAINT [FK_Invoice_Invoice Type] FOREIGN KEY([type_id])
REFERENCES [dbo].[Invoice Type] ([id])
GO
ALTER TABLE [dbo].[Invoice] CHECK CONSTRAINT [FK_Invoice_Invoice Type]
GO
ALTER TABLE [dbo].[Invoice] WITH CHECK ADD CONSTRAINT [FK_Invoice_Student] FOREIGN KEY([student_id])
REFERENCES [dbo].[Student] ([id])
GO
ALTER TABLE [dbo].[Invoice] CHECK CONSTRAINT [FK_Invoice_Student]
GO
ALTER TABLE [dbo].[Price] WITH CHECK ADD CONSTRAINT [FK_Price_Price Type] FOREIGN KEY([price_type])
REFERENCES [dbo].[Price Type] ([id])
GO
ALTER TABLE [dbo].[Price] CHECK CONSTRAINT [FK_Price_Price Type]
GO
ALTER TABLE [dbo].[Request] WITH CHECK ADD CONSTRAINT [FK_Request_Request Type] FOREIGN KEY([type_id])
REFERENCES [dbo].[Request Type] ([id])
GO
ALTER TABLE [dbo].[Request] CHECK CONSTRAINT [FK_Request_Request Type]
GO
ALTER TABLE [dbo].[Request] WITH CHECK ADD CONSTRAINT [FK_Request_Student] FOREIGN KEY([student_id])
REFERENCES [dbo].[Student] ([id])
GO
ALTER TABLE [dbo].[Request] CHECK CONSTRAINT [FK_Request_Student]
GO
ALTER TABLE [dbo].[Room] WITH CHECK ADD CONSTRAINT [FK_Room_Floor] FOREIGN KEY([floor_id])
REFERENCES [dbo].[Floor] ([id])
GO
ALTER TABLE [dbo].[Room] CHECK CONSTRAINT [FK_Room_Floor]
GO
ALTER TABLE [dbo].[Room Usage] WITH CHECK ADD CONSTRAINT [FK_Room Usage_Room] FOREIGN KEY([room_id])
REFERENCES [dbo].[Room] ([id])
GO
ALTER TABLE [dbo].[Room Usage] CHECK CONSTRAINT [FK_Room Usage_Room]
GO
ALTER TABLE [dbo].[Student] WITH CHECK ADD CONSTRAINT [FK_Student_Bed] FOREIGN KEY([bed_id])
REFERENCES [dbo].[Bed] ([id])
GO
ALTER TABLE [dbo].[Student] CHECK CONSTRAINT [FK_Student_Bed]
GO
Markup
Description
No description
To share this paste please copy this url and send to your friends
RAW Paste Data