0% found this document useful (0 votes)
16 views2 pages

Ghshalgalt

The document creates a database called HOTEL and defines tables for Rooms, Employees, Customers, Bookings and Services. Tables define columns, data types, primary keys and foreign key relationships. Check constraints are added to validate column values.

Uploaded by

tushigsaikhna
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views2 pages

Ghshalgalt

The document creates a database called HOTEL and defines tables for Rooms, Employees, Customers, Bookings and Services. Tables define columns, data types, primary keys and foreign key relationships. Check constraints are added to validate column values.

Uploaded by

tushigsaikhna
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
You are on page 1/ 2

CREATE DATABASE HOTEL;

USE HOTEL;

CREATE TABLE Rooms


(
RoomType VARCHAR (1) NOT NULL,
RoomNo NUMERIC (18) NOT NULL,
Comments VARCHAR (250),
RoomStatus VARCHAR (1) NOT NULL,
Price MONEY NOT NULL,
CONSTRAINT [PK_Rooms ] PRIMARY KEY CLUSTERED ([RoomNo] ASC),
CONSTRAINT [CK_Price] CHECK (case when [RoomType]='S' then (100) when
[RoomType]='D' then (200) when [RoomType]='T' then (350) when [RoomType]='DR' then
(500) else (0) end=(1)),
CONSTRAINT [CK_RoomType] CHECK ([RoomType]='DR' OR [RoomType]='T' OR
[RoomType]='D' OR [RoomType]='S')
);

GO
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'S - single
room, D - double room, T - triple room, DR - deluxe room', @level0type = N'SCHEMA',
@level0name = N'dbo', @level1type = N'TABLE', @level1name = N'Rooms ', @level2type
= N'CONSTRAINT', @level2name = N'CK_RoomType';

CREATE TABLE Employee


(
Firstname CHAR (15) NOT NULL,
Lastname CHAR (15) NOT NULL,
Phonenumber VARCHAR (8) NOT NULL,
Position VARCHAR (1) NOT NULL,
EmployeeId VARCHAR (5) NOT NULL,
CONSTRAINT [PK_Employee] PRIMARY KEY CLUSTERED ([EmployeeId] ASC),
CONSTRAINT [CK_Phonenumber] CHECK ([Phonenumber] like '[0-9] [0-9] [0-9] [0-
9] [0-9] [0-9] [0-9] [0-9]'),
CONSTRAINT [CK_Position] CHECK ([Position]='LS' OR [Position]='H' OR
[Position]='C')
);

CREATE TABLE Customers


(
Firstname CHAR (15) NOT NULL,
Lastname CHAR (15) NOT NULL,
Phonenumber VARCHAR (8) NOT NULL,
CustomerId VARCHAR (5) NOT NULL,
CONSTRAINT [PK_Customers ] PRIMARY KEY CLUSTERED (CustomerId),
CONSTRAINT [CK_Phonenumber_1] CHECK ([Phonenumber] like '[0-9] [0-9] [0-9]
[0-9] [0-9] [0-9] [0-9] [0-9]')
);

CREATE TABLE Booking


(
RoomNo NUMERIC (18) NOT NULL,
CustomerId VARCHAR (5) NOT NULL,
DateFrom DATE NOT NULL,
DateTo INT NOT NULL,
CONSTRAINT [PK_Booking ] PRIMARY KEY CLUSTERED (RoomNo, CustomerId),
CONSTRAINT [FK_Booking _Customers _1] FOREIGN KEY (CustomerId)
REFERENCES [dbo].[Customers] (CustomerId),
CONSTRAINT [FK_Booking _Rooms ] FOREIGN KEY (RoomNo) REFERENCES
[dbo].[Rooms] (RoomNo)
);

CREATE TABLE Services


(
RoomNo NUMERIC (18) NOT NULL,
EmployeeId VARCHAR (5) NOT NULL,
ServiceType VARCHAR (1) NOT NULL,
ServicePrice MONEY NOT NULL,
CONSTRAINT PK_Services PRIMARY KEY CLUSTERED (RoomNo,EmployeeId,
ServiceType),
CONSTRAINT CK_ServicePrice CHECK (case when [ServicePrice]='R' then (20) when
[ServicePrice]='L' then (10) when [ServicePrice]='T' then (10) else (0) end=(1)),
CONSTRAINT CK_ServiceType CHECK ([ServiceType]='T' OR [ServiceType]='L' OR
[ServiceType]='R'),
CONSTRAINT FK_Services_Rooms FOREIGN KEY ([RoomNo]) REFERENCES
[dbo].[Rooms ] ([RoomNo]),
CONSTRAINT FK_Services_Employee FOREIGN KEY ([EmployeeId])
REFERENCES [dbo].[Employee] ([EmployeeId])
);

GO
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'Restaurant -
R, L - Laundry, T-Transport. ', @level0type = N'SCHEMA', @level0name = N'dbo',
@level1type = N'TABLE', @level1name = N'Services', @level2type = N'CONSTRAINT',
@level2name = N'CK_ServiceType';

You might also like