Microsoft-Northwind(電子商務)-數據庫設計


ylbtech-DatabaseDesgin:微軟官方提供-Northwind(電子商務)-數據庫設計
 
1.A,數據庫關系圖

 

1.B,數據庫設計腳本(此腳本的注釋,是在下根據一些資料所注,如有不妥當之處,望給予矯正,謹謝。)
View Code
-- ============================================= 
-- ylb:電子商務模板 
-- author:YUANBO 
-- development time:2011-11-9 
-- thank you:LiuGaiZhen 
-- ============================================= 
USE master 
GO 
  
-- Drop the database if it already exists 
IF  EXISTS ( 
    SELECT name 
        FROM sys.databases  
        WHERE name = N'EShop'
) 
DROP DATABASE EShop 
GO 
  
CREATE DATABASE EShop 
GO 
use EShop 
  
go 
-- ============================================= 
-- 1,供應商 
-- ============================================= 
create table Suppliers 
( 
SupplierID int identity(1,1) primary key,   --供應商ID [PK] 
CompanyName nvarchar(40) not null,          --公司名稱 
ContactName nvarchar(30),           --聯系人姓名 
ContactTitle nvarchar(30),          --聯系人頭銜 
[Address] nvarchar(60),             --地址 
  
City nvarchar(15),                  --城市 
Region nvarchar(15),                --地區 
PostalCode nvarchar(15),            --郵政編碼 
Country nvarchar(24),               --國家 
Phone nvarchar(24),                 --電話 
  
Fax nvarchar(24),           --傳真 
HomePage ntext              --主頁 
) 
  
go 
-- ============================================= 
-- 2,類別 
-- ============================================= 
create table Categories 
( 
CategoryID int identity(1,1) primary key,   --類別ID  [PK] 
CategoryName nvarchar(15) not null, --類別名稱 
[Description] ntext,                --說明 
Picture image                       --圖片 
) 
  
go 
-- ============================================= 
--3,產品  
-- ============================================= 
create table Products 
( 
ProductID int identity primary key, --產品ID『PK』 
ProductName nvarchar(40) not null,  --產品名稱 
SupplierID int foreign key references Suppliers(SupplierID),                        --供應商ID 
CategoryID int foreign key references Categories(CategoryID),                   --類別ID 
QuantityPerUnit nvarchar(20),   --單位數量 
  
UnitPrice money,            --單價 
UnitsInStock smallint default(0) check(UnitsInStock>=0),     --庫存量 
UnitsOnOrder smallint default(0) check(UnitsOnOrder>=0),     --訂購量 
ReorderLevel smallint default(0) check(ReorderLevel>=0),     --再訂購量 
Discontinued bit            --中止 
) 
  
go 
-- ============================================= 
-- 4,訂單明細 
-- ============================================= 
create table OrderDetails 
( 
OrderID int identity(1,1),      --訂單ID 
ProductID int,      --產品ID   
UnitPrice money not null,   --單價 
Quantity smallint not null, --數量 
Discount real not null,     --折扣 
  
primary key(OrderID,ProductID)  --聯合主鍵 
) 
  
go 
-- ============================================= 
-- 5,雇員 
-- P:1,ReportsTo; 2,baseID 
-- ============================================= 
create table Employees 
( 
EmployeeID int identity(1,1) primary key,   --雇員ID【PK】 
lastName nvarchar(20) not null,             --姓氏 
FirstName nvarchar(10) not null,            --名字 
Title nvarchar(30),     --頭銜 
TitleOfCourtesy nvarchar(25),       --尊稱 
  
BirthDate datetime,     --出生日期 
HireDate datetime,      --雇佣日期 
[Address] nvarchar(50), --地址 
City nvarchar(15),      --城市 
Region nvarchar(15),    --地區 
  
PostalCode nvarchar(10),    --郵政編碼 
Country nvarchar(15),       --國家 
HomePhone nvarchar(24),     --家庭電話 
Extension nvarchar(4),      --分機 
Photo image,                --照片 
  
Notes ntext,        --備注 
--ReportsTo int FK 
PhotoPath nvarchar(255) --圖片地址 
--baseID    --上級編號 
) 
  
go 
-- ============================================= 
-- 6,客戶 
-- ============================================= 
create table Customers 
( 
CustomerID nchar(5) primary key,    --客戶ID【PK】 
CompanyName nvarchar(40) not null,  --公司名稱 
ContactName nvarchar(30),           --聯系人姓名 
ContactTitle nvarchar(30),          --聯系人頭銜 
[Address] nvarchar(60),             --地址 
  
City nvarchar(15),      --城市 
Region nvarchar(15),    --地區 
PostalCode nvarchar(15),--郵政編號   
Country nvarchar(24),   --國家 
Phone nvarchar(24),     --電話 
  
Fax nvarchar(24)        --傳真 
) 
  
go 
-- ============================================= 
-- 7,客戶演示圖形 
-- ============================================= 
create table CustomerDemoGraphics 
( 
CustomerTypeID nchar(10) primary key,   --客戶演示圖形ID 【PK】 
CustomerDesc ntext                      --客戶描述 
) 
  
go 
-- ============================================= 
-- 7,客戶演示圖形 
-- ============================================= 
create table CustomerCustomerDemo 
( 
CustomerID nchar(5) foreign key references Customers(CustomerID),   --客戶ID【PK,FK】 
CustomerTypeID nchar(10) foreign key references CustomerDemoGraphics(CustomerTypeID), --客戶演示圖形ID【PK,FK】 
primary key(CustomerID,CustomerTypeID) 
) 
  
go 
-- ============================================= 
-- 7,訂單 
-- ============================================= 
create table Orders 
( 
OrderID int identity primary key,   --訂單ID【PK】 
CustomerID nchar(5) foreign key references Customers(CustomerID),   --客戶ID【FP】 
EmployeeID int foreign key references Employees(EmployeeID),    --雇員ID【FP】 
OrderDate datetime,     --訂購日期 
RequiredDate datetime,  --到貨日期 
  
ShippedDate datetime,   --發貨日期 
--ShipVia int FK        --運貨商 
Fright money,           --運貨費 
ShipName nvarchar(15),      --貨主名稱 
ShipAddress nvarchar(60),   --貨主地址 
  
ShipCity nvarchar(15),      --貨主城市 
ShipRegion nvarchar(15),    --貨主地區 
ShipPostalCode nvarchar(10),--貨主郵政編碼     
ShipContry nvarchar(15)     --貨主國家 
) 
  
-- ============================================= 
-- 8,運貨商 
-- ============================================= 
create table Shippers 
( 
ShipperID int identity primary key,     --運貨商ID【PK】 
CompanyName nvarchar(40) not null,      --公司名稱 
Phone nvarchar(24)                      --電話 
) 
  
print 'ylb, tech 創建電子商務數據庫完成' 
1.C,功能實現代碼

 無操作

warn 作者:ylbtech
出處:http://ylbtech.cnblogs.com/
本文版權歸作者和博客園共有,歡迎轉載,但未經作者同意必須保留此段聲明,且在文章頁面明顯位置給出原文連接,否則保留追究法律責任的權利。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM