-
Notifications
You must be signed in to change notification settings - Fork 1
/
BookStore.sql
160 lines (81 loc) · 2.94 KB
/
BookStore.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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
create database BookStoreDB
use BookStoreDB
create table Books
(
IdBook int primary key IDENTITY (1,1) NOT NULL,
BookName nvarchar(max) NOT NULL,
BookPrice money NOT NULL,
BookQuantity bigint NOT NULL,
Constraint CK_BookName Check(BookName <>' '),
)
create table Press
(
IdPress int primary key IDENTITY (1,1) NOT NULL,
PressName nvarchar(max) NOT NULL,
PressYear nvarchar(max) NOT NULL,
Constraint CK_PressName Check(PressName <>' '),
Constraint CK_PressYear Check(PressYear <>' ')
)
create table Authors
(
IdAuthor int primary key IDENTITY (1,1) NOT NULL,
Author1 nvarchar(max) NOT NULL,
Author2 nvarchar(max) NOT NULL,
Constraint CK_AuthorFirtName Check(Author1 <>' '),
Constraint CK_AuthorLastName Check(Author2 <>' ')
)
create table BookDetails
(
IdBookDetail int primary key IDENTITY (1,1) NOT NULL,
BookId_forBookDetail int NOT NULL,
AuthorId_forBookDetail int NOT NULL,
PressId_forBookDetail int NOT NULL,
Constraint FK_BookId_forBA Foreign key (BookId_forBookDetail) References Books(IdBook) On Delete CASCADE On Update CASCADE,
Constraint FK_AuthorId_forBA Foreign key (AuthorId_forBookDetail) References Authors(IdAuthor) On Delete CASCADE On Update CASCADE,
Constraint FK_PressId_forBA Foreign key (PressId_forBookDetail) References Press(IdPress) On Delete CASCADE On Update CASCADE
)
CREATE TABLE BookStoreDB.dbo.Customers
(
IdCustomers int primary key IDENTITY (1,1) NOT NULL,
[Name of Customers] nvarchar(100) NOT NULL,
[Passwords of Customers] nvarchar(100) NOT NULL,
Constraint CK_Name_of_Customers Check([Name of Customers] <>' '),
Constraint CK_Passwords_of_Customers Check([Passwords of Customers] <>' '),
Constraint UK_Passwords_of_Customers Unique([Passwords of Customers])
)
CREATE TABLE BookStoreDB.dbo.Admins
(
IdAdmins int primary key IDENTITY (1,1) NOT NULL,
[Name of Admins] nvarchar(100) NOT NULL,
[Passwords of Admins] nvarchar(100) NOT NULL,
Constraint CK_Name_of_Admins Check([Name of Admins] <>' '),
Constraint CK_Passwords_of_Admins Check([Passwords of Admins] <>' '),
Constraint UK_Passwords_of_Admins Unique([Passwords of Admins])
)
create table Cashregisters
(
IdCashregister int primary key IDENTITY (1,1) NOT NULL,
Profit money,
CustomersId_for_Cashregister int NOT NULL,
BookId_forCashregister int NOT NULL,
Constraint FK_CustomersIdforOrders Foreign key (CustomersId_for_Cashregister) References Customers(IdCustomers) On Delete CASCADE On Update CASCADE,
Constraint FK_BookId_forC Foreign key (BookId_forCashregister) References Books(IdBook) On Delete CASCADE On Update CASCADE
)
-- GetAll
select
*
from
BookStoreDB.dbo.Books
Inner Join
BookStoreDB.dbo.BookDetails
On
BookStoreDB.dbo.Books.IdBook=BookStoreDB.dbo.BookDetails.BookId_forBookDetail
Inner Join
BookStoreDB.dbo.Authors
On
BookStoreDB.dbo.Authors.IdAuthor=BookStoreDB.dbo.BookDetails.AuthorId_forBookDetail
select *from Books
select *from Authors
select *from Press
select *from BookDetails
select *from Cashregisters