zoukankan      html  css  js  c++  java
  • MicrosoftNorthwind(电子商务)数据库设计

    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/
    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
  • 相关阅读:
    poj 2528 Mayor's posters (线段树+离散化)
    poj 1201 Intervals (差分约束)
    hdu 4109 Instrction Arrangement (差分约束)
    poj 1195 Mobile phones (二维 树状数组)
    poj 2983 Is the Information Reliable? (差分约束)
    树状数组 讲解
    poj 2828 Buy Tickets (线段树)
    hdu 1166 敌兵布阵 (树状数组)
    Ubuntu网络配置
    Button控制窗体变量(开关控制灯的状态)
  • 原文地址:https://www.cnblogs.com/ylbtech/p/2917899.html
Copyright © 2011-2022 走看看