-
Notifications
You must be signed in to change notification settings - Fork 4
/
StoreDB_Script.sql
59 lines (50 loc) · 1.64 KB
/
StoreDB_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
create database StoreDB
go
use StoreDB
go
create table Employee(
ID int identity(1,1) primary key not null,
FirstName varchar(50) not null,
LastName varchar(50) not null,
UserName varchar(32) not null,
Password varchar(32) not null
)
create table Customer(
ID int identity(1,1) primary key not null,
FirstName varchar(50) not null,
LastName varchar(50) not null,
UserName varchar(32) not null,
Password varchar(32) not null
)
insert into Customer values ('Juan', 'Perez', '123',
CONVERT(VARCHAR(32), HashBytes('MD5', 'abc'), 2))
select * from customer
create table Product(
ID int identity(1,1) primary key not null,
Name varchar(255) not null,
UnitPrice decimal(8,2) not null
)
create table OrderStatus(
ID int identity(1,1) primary key not null,
Name varchar(255) not null
)
insert into OrderStatus(Name)
values ('1-Unpaid'), ('2-Paid'), ('3-Processing'), ('4-Shipped'), ('5-Delivered')
create table CustomerOrder(
ID int identity(1,1) primary key not null,
CustomerID int not null,
Date smalldatetime not null,
OrderStatusID int not null,
Amount decimal(10,2) not null,
constraint FK_Customer_CustomerOrder foreign key (CustomerID) references Customer(ID),
constraint FK_OrderStatus_CustomerOrder foreign key (OrderStatusID) references OrderStatus(ID)
)
create table OrderDetail(
CustomerOrderID int not null,
ProductID int not null,
Quantity int not null,
Amount decimal(10,2) not null,
constraint FK_CustomerOrder_OrderDetail foreign key (CustomerOrderID) references CustomerOrder(ID),
constraint FK_Product_OrderDetail foreign key (ProductID) references Product(ID),
constraint PK_OrderDetail primary key (CustomerOrderID, ProductID)
)