-
Notifications
You must be signed in to change notification settings - Fork 0
/
SQL_Netflix_DB_Example(DDL).sql
96 lines (61 loc) · 2.54 KB
/
SQL_Netflix_DB_Example(DDL).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
use NetflixDB
Create table [dbo].[Movies]
(
[MovieID] INT IDENTITY (1,1) NOT NULL,
[MovieName] NVARCHAR(40) NOT NULL,
[GenreID] INT NOT NULL,
[ActorID] INT NOT NULL,
[Vision Date] DATE NOT NULL,
[Access] BIT NOT NULL, /*HOcAyA sOr BÝT*/
CONSTRAINT [PK_MOVÝES] PRIMARY KEY CLUSTERED ([MovieID] ASC),
/*CONSTRAINT [FK_Genres_GenreID] Foreign Key ([GenreID]) REFERENCES [dbo]. [Genres] ([GenreID]),*/
/* CONSTRAINT [FK_Actors_ActorID] Foreign Key ([ActorID]) REFERENCES [dbo]. [Acthors] ([ActhorID])*/
)
/*ALTER TABLE Movies ADD Foreign Key (GenreID) REFERENCES [dbo].[Genres] ([GenreID])*/
/*Çalýþtýrmadan dahi yazým sýrasý çok önemli çünkü yazýlmamýþ veriYÝ references veremezsýn kýzrarýr:D */
go Create Table [dbo]. [Actors]
(
[ActorID] INT IDENTITY (1,1) NOT NULL ,
[FirstName] NVARCHAR(40) NOT NULL,
[LastName] NVARCHAR(40) NOT NULL,
[City] NVARCHAR(20) NOT NULL,
[Country] NVARCHAR(20) NOT NULL,
CONSTRAINT [PK_ACTORS] PRIMARY KEY CLUSTERED ([ActorID] ASC),
) go
go Create Table [dbo]. [ActorDetails]
(
[ActorID] int NOT NULL,
[MovieID] int NOT NULL,
CONSTRAINT [FK_AwardDetails_MoviesID] FOREIGN KEY ([MovieID]) REFERENCES [dbo]. [Movies] ([MovieID]),
CONSTRAINT [FK_AwardDetails_ActorID] FOREIGN KEY ([ActorID]) REFERENCES [dbo]. [Actors] ([ActorID])
) go
go Create Table [dbo]. [Genres]
(
[GenreID] INT IDENTITY(1,1) NOT NULL,
[GenreName] NVARCHAR(40) NOT NULL,
[Subgenre] NVARCHAR(40) NOT NULL,
[Description] NVARCHAR(500) NOT NULL,
CONSTRAINT [PK_GENRES] PRIMARY KEY CLUSTERED ([GenreID] ASC),
) go
go Create Table [dbo]. [Users]
(
[UserID] INT IDENTITY (1,1) NOT NULL,
[UserName] NVARCHAR(40) NOT NULL,
[UserLastName] NVARCHAR(40) NOT NULL,
[BirthDate] DATE NOT NULL,
[UserNick] NVARCHAR(15) NOT NULL,
[Account Date] DATETIME2(7) NOT NULL,/*7 NE ANLAMA GELÝYOR*/
[Country] NVARCHAR(20) NOT NULL,
CONSTRAINT [PK_Users] PRIMARY KEY ([UserID] ASC)
) go
go Create Table [dbo]. [UserDetails]
(
[UserID] INT NOT NULL,
[GenreID] INT NOT NULL,
[MovieID] INT NOT NULL,
CONSTRAINT [FK_UserDatails_UserID] Foreign Key ([UserID]) REFERENCES [dbo]. [Users] ([UserID]),
CONSTRAINT [FK_Genres_GenreID] Foreign Key ([GenreID]) REFERENCES [dbo]. [Genres] ([GenreID]),
CONSTRAINT [FK_Movies_MovieID] Foreign Key ([MovieID]) REFERENCES [dbo]. [Movies] ([MovieID])
) go
/*1- Tablo oluþma sýrasý ve foreign key */
/*2-bit veri tipi*/