0% found this document useful (0 votes)
8 views

database2024

Uploaded by

minhhoang.cxui
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

database2024

Uploaded by

minhhoang.cxui
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

--New Database: MyStore

-- Bang User: quan ly ca tai khoan cua Khach hang va Admin


CREATE TABLE [dbo].[User] (
[Username] NVARCHAR (255) NOT NULL,
[Password] NCHAR (50) NOT NULL,
[UserRole] NCHAR (1) NOT NULL,
PRIMARY KEY CLUSTERED ([Username] ASC)
);

--Bang Customer: luu thong tin khach hang


CREATE TABLE [dbo].[Customer] (
[CustomerID] INT IDENTITY (1, 1) NOT NULL,
[CustomerName] NVARCHAR (MAX) NOT NULL,
[CustomerPhone] NVARCHAR (15) NOT NULL,
[CustomerEmail] NVARCHAR (MAX) NULL,
[CustomerAddress] NVARCHAR (MAX) NULL,
[Username] NVARCHAR (255) NOT NULL,
PRIMARY KEY CLUSTERED ([CustomerID] ASC),
CONSTRAINT [FK_User_Customer] FOREIGN KEY ([Username]) REFERENCES [dbo].[User]
([Username])
);

--Bang Category: luu thong tin danh muc san pham


CREATE TABLE [dbo].[Category] (
[CategoryID] INT IDENTITY (1, 1) NOT NULL,
[CategoryName] NVARCHAR (MAX) NOT NULL,
PRIMARY KEY CLUSTERED ([CategoryID] ASC)
);
--Bang Product: luu thong tin san pham
CREATE TABLE [dbo].[Product] (
[ProductID] INT IDENTITY (1, 1) NOT NULL,
[CategoryID] INT NOT NULL,
[ProductName] NVARCHAR (MAX) NOT NULL,
[ProductDecription] NVARCHAR (MAX) NOT NULL,
[ProductPrice] DECIMAL (18, 2) NOT NULL,
[ProductImage] NVARCHAR (MAX) NULL,
PRIMARY KEY CLUSTERED ([ProductID] ASC),
CONSTRAINT [FK_Pro_Category] FOREIGN KEY ([CategoryID]) REFERENCES [dbo].
[Category] ([CategoryID])
);

--Bang Order: luu thong tin don hang cua khach hang
CREATE TABLE [dbo].[Order] (
[OrderID] INT IDENTITY (1, 1) NOT NULL,
[CustomerID] INT NOT NULL,
[OrderDate] DATE NOT NULL,
[TotalAmount] DECIMAL (18, 2) NOT NULL,
[PaymentStatus] NVARCHAR (MAX) NULL,
[AddressDelivery] NVARCHAR (MAX) NOT NULL,
PRIMARY KEY CLUSTERED ([OrderID] ASC),
FOREIGN KEY ([CustomerID]) REFERENCES [dbo].[Customer] ([CustomerID])
);
--Bang OrderDetail: luu thong tin chi tiet cac san pham co trong don hang
CREATE TABLE [dbo].[OrderDetail] (
[ID] INT IDENTITY (1, 1) NOT NULL,
[ProductID] INT NOT NULL,
[OrderID] INT NOT NULL,
[Quantity] INT NOT NULL,
[UnitPrice] DECIMAL (18, 2) NOT NULL,
PRIMARY KEY CLUSTERED ([ID] ASC),
FOREIGN KEY ([ProductID]) REFERENCES [dbo].[Product] ([ProductID]),
FOREIGN KEY ([OrderID]) REFERENCES [dbo].[Order] ([OrderID])
);

ALTER AUTHORIZATION ON DATABASE::MyStore TO sa;

You might also like