-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.sql
126 lines (110 loc) · 3.55 KB
/
script.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
create database OLX
go
use OLX
go
SET ANSI_WARNINGS OFF
CREATE TABLE Locale
(
LocaleID INT PRIMARY KEY IDENTITY(1, 1),
residenceBlock VARCHAR(5) NOT NULL,
society VARCHAR(40) NOT NULL,
city VARCHAR(20) NOT NULL,
residenceState VARCHAR(20) NOT NULL
)
CREATE TABLE Users
(
UserID INT PRIMARY KEY IDENTITY(1, 1),
fName VARCHAR(40) NOT NULL,
lName VARCHAR(40) NOT NULL,
email VARCHAR(60) NOT NULL UNIQUE,
userPassword VARCHAR(30) NOT NULL,
joinDate date NOT NULL,
phone VARCHAR(20),
userLocation INT FOREIGN KEY REFERENCES Locale(LocaleID) ON DELETE NO ACTION ON UPDATE NO ACTION,
)
CREATE TABLE Advertisement
(
advertisementID INT PRIMARY KEY IDENTITY(1, 1),
adPosterID INT FOREIGN KEY REFERENCES Users(UserID) ON DELETE NO ACTION ON UPDATE NO ACTION,
title VARCHAR(250) NOT NULL,
price INT NOT NULL,
adDescription VARCHAR(250) NOT NULL,
approvalStatus VARCHAR(250),
category VARCHAR(250) NOT NULL
)
CREATE TABLE Jobs
(
JobID INT PRIMARY KEY IDENTITY(1, 1),
AdvertisementID INT FOREIGN KEY REFERENCES Advertisement(advertisementID) ON DELETE SET NULL ON UPDATE NO ACTION,
companyName VARCHAR(70) NOT NULL,
jobDescription VARCHAR(250) NOT NULL
)
CREATE TABLE Pets
(
PetID INT PRIMARY KEY IDENTITY(1, 1),
AdvertisementID INT FOREIGN KEY REFERENCES Advertisement(advertisementID) ON DELETE SET NULL ON UPDATE NO ACTION,
breed VARCHAR(40) NOT NULL
)
CREATE TABLE Electronics
(
ElectronicID INT PRIMARY KEY IDENTITY(1, 1),
AdvertisementID INT FOREIGN KEY REFERENCES Advertisement(advertisementID) ON DELETE SET NULL ON UPDATE NO ACTION,
condition VARCHAR(50),
make VARCHAR(30) NOT NULL
)
CREATE TABLE Property
(
PropertyID INT PRIMARY KEY IDENTITY(1, 1),
AdvertisementID INT FOREIGN KEY REFERENCES Advertisement(advertisementID) ON DELETE SET NULL ON UPDATE NO ACTION,
category VARCHAR(240)
)
CREATE TABLE House
(
HouseID INT PRIMARY KEY IDENTITY(1, 1),
PropertyID INT FOREIGN KEY REFERENCES Property(PropertyID) ON DELETE SET NULL ON UPDATE NO ACTION,
noOfBedrooms INT NOT NULL,
noOfBathrooms INT NOT NULL
)
CREATE TABLE Mobile
(
MobileID INT PRIMARY KEY IDENTITY(1, 1),
AdvertisementID INT FOREIGN KEY REFERENCES Advertisement(advertisementID) ON DELETE SET NULL ON UPDATE NO ACTION,
condition VARCHAR(50),
make VARCHAR(30) NOT NULL
)
CREATE TABLE Vehicle
(
registrationNo INT PRIMARY KEY IDENTITY(1, 1),
AdvertisementID INT FOREIGN KEY REFERENCES Advertisement(advertisementID) ON DELETE SET NULL ON UPDATE NO ACTION,
registrationYear INT NOT NULL,
make VARCHAR(30) NOT NULL,
condition VARCHAR(30) NOT NULL,
kmDriven INT NOT NULL,
fuelEfficiency FLOAT NOT NULL
)
CREATE TABLE Followings
(
FollowerID INT FOREIGN KEY REFERENCES Users(UserID) ON DELETE CASCADE ON UPDATE NO ACTION,
FolloweeID INT FOREIGN KEY REFERENCES Users(UserID) ON DELETE NO ACTION ON UPDATE NO ACTION,
PRIMARY KEY(FollowerID, FolloweeID)
)
CREATE TABLE Likes
(
UserID INT FOREIGN KEY REFERENCES Users(UserID) ON DELETE CASCADE ON UPDATE NO ACTION,
AdvertisementID INT FOREIGN KEY REFERENCES Advertisement(advertisementID) ON DELETE CASCADE ON UPDATE NO ACTION,
PRIMARY KEY(UserID, AdvertisementID)
)
Select * from Advertisement a join Pets j on a.advertisementID=j.AdvertisementID
select * from Users
select * from Advertisement
select * from Jobs
select * from Pets
select * from Electronics
select * from Property
select * from House
select * from Mobile
select * from Vehicle
select * from Locale
select * from Advertisement
select * from Followings
select * from Likes