-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCreateMovieDB.sql
73 lines (57 loc) · 1.47 KB
/
CreateMovieDB.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
--Database
Create Database MovieDataDB
go
use MovieDataDB
go
--Table
Create table Directors(
Id int not null primary key identity (1,1),
FullName nvarchar(150) not null
)
Create table Movies(
MovieID int not null primary key identity(1,1),
MovieName nvarchar(255) not null,
Description nvarchar(1000) not null,
Duration smallint,
Year int,
DirectorId int foreign key references Directors(Id)
)
Create table Genres(
GenreID int not null primary key identity(1,1),
Name nvarchar(30) not null
)
Create table MovieGenres(
Movie_Id int not null foreign key references Movies(MovieID),
Genre_Id int not null foreign key references Genres(GenreID)
)
Create table Users (
UserID int not null primary key identity(1,1),
FirstName nvarchar(100) not null,
LastName nvarchar(100) not null,
UserName nvarchar(100) not null,
Password nvarchar(8) not null,
Email nvarchar(255) not null,
)
Create table Comments(
Id int not null primary key identity(1,1),
Body nvarchar(Max),
CreatedDate datetime default getdate(),
UserId int not null foreign key references Users(UserID),
MovieId int not null foreign key references Movies(MovieID)
)
--Alter
Alter table Users
add PhoneNumber char(11) --Add cloumn
Alter table Users
add Address nvarchar(500) -- add column
Alter table Movies
add Rating smallint -- add column
--Drop
Create table TestTable(ID int primary key)
drop table TestTable --drop table
--Drop cloumn
Alter table Users
drop column Address
--Drop Database
--Use master
-- drop database MovieDB