---------------------------------------------------------------------
-- Script that creates the sample database InsideTSQL2008
--
-- Supported versions of SQL Server: 2005, 2008
--
-- Based originally on the Northwind sample database
-- with changes in both schema and data to fit the book's needs
--
-- Last updated: 20080910
----------------------------------------------------------------------
---------------------------------------------------------------------
-- Create Database
---------------------------------------------------------------------
USE master;
-- Drop database
IF DB_ID('InsideTSQL2008') IS NOT NULL DROP DATABASE InsideTSQL2008;
-- If database could not be created due to open connections, abort
IF @@ERROR = 3702
RAISERROR('Database cannot be dropped because there are still open connections.', 127, 127) WITH NOWAIT, LOG;
-- Create database
CREATE DATABASE InsideTSQL2008;
GO
USE InsideTSQL2008;
GO
---------------------------------------------------------------------
-- Create Schemas
---------------------------------------------------------------------
CREATE SCHEMA HR AUTHORIZATION dbo;
GO
CREATE SCHEMA Production AUTHORIZATION dbo;
GO
CREATE SCHEMA Sales AUTHORIZATION dbo;
GO
---------------------------------------------------------------------
-- Create Tables
---------------------------------------------------------------------
-- Create table HR.Employees
CREATE TABLE HR.Employees
(
empid INT NOT NULL IDENTITY,
lastname NVARCHAR(20) NOT NULL,
firstname NVARCHAR(10) NOT NULL,
title NVARCHAR(30) NOT NULL,
titleofcourtesy NVARCHAR(25) NOT NULL,
birthdate DATETIME NOT NULL,
hiredate DATETIME NOT NULL,
address NVARCHAR(60) NOT NULL,
city NVARCHAR(15) NOT NULL,
region NVARCHAR(15) NULL,
postalcode NVARCHAR(10) NULL,
country NVARCHAR(15) NOT NULL,
phone NVARCHAR(24) NOT NULL,
mgrid INT NULL,
CONSTRAINT PK_Employees PRIMARY KEY(empid),
CONSTRAINT FK_Employees_Employees FOREIGN KEY(mgrid)
REFERENCES HR.Employees(empid),
CONSTRAINT CHK_birthdate CHECK(birthdate <= CURRENT_TIMESTAMP)
);
CREATE NONCLUSTERED INDEX idx_nc_lastname ON HR.Employees(lastname);
CREATE NONCLUSTERED INDEX idx_nc_postalcode ON HR.Employees(postalcode);
-- Create table Production.Suppliers
CREATE TABLE Production.Suppliers
(
supplierid INT NOT NULL IDENTITY,
companyname NVARCHAR(40) NOT NULL,
contactname NVARCHAR(30) NOT NULL,
contacttitle NVARCHAR(30) NOT NULL,
address NVARCHAR(60) NOT NULL,
city NVARCHAR(15) NOT NULL,
region NVARCHAR(15) NULL,
postalcode NVARCHAR(10) NULL,
country NVARCHAR(15) NOT NULL,
phone NVARCHAR(24) NOT NULL,
fax NVARCHAR(24) NULL,
CONSTRAINT PK_Suppliers PRIMARY KEY(supplierid)
);
CREATE NONCLUSTERED INDEX idx_nc_companyname ON Production.Suppliers(companyname);
CREATE NONCLUSTERED INDEX idx_nc_postalcode ON Production.Suppliers(postalcode);
-- Create table Production.Categories
CREATE TABLE Production.Categories
(
categoryid INT NOT NULL IDENTITY,
categoryname NVARCHAR(15) NOT NULL,
description NVARCHAR(200) NOT NULL,
CONSTRAINT PK_Categories PRIMARY KEY(categoryid)
);
CREATE INDEX categoryname ON Production.Categories(categoryname);
-- Create table Production.Products
CREATE TABLE Production.Products
(
productid INT NOT NULL IDENTITY,
productname NVARCHAR(40) NOT NULL,
supplierid INT NOT NULL,
categoryid INT NOT NULL,
unitprice MONEY NOT NULL
CONSTRAINT DFT_Products_unitprice DEFAULT(0),
discontinued BIT NOT NULL
CONSTRAINT DFT_Products_discontinued DEFAULT(0),
CONSTRAINT PK_Products PRIMARY KEY(productid),
CONSTRAINT FK_Products_Categ�
producer
- 粉丝: 3
- 资源: 10
最新资源
- Python初学者教程
- ABAQUS模型:钙质土中重力串锚水平承载力特性有限元研究 使用ABAQUS软件Standard,模拟了海底重力锚在钙质土中的水平极限承载力,土体采用莫尔库伦本构,重力锚为钢制,同时受到重力与浮力作
- 新能源动力电池电芯绝缘测试机sw21可编辑全套技术资料100%好用.zip
- 人工蜂鸟群算法优化BP神经网络(AHA-BP)实现数据预测分类的matlab代码
- Debian新维护人员手册(maint-guide.zh-cn.pdf)
- 基于线性模型预测控制(LMPC)的四旋翼飞行器(UAV)控制
- 基于微信平台的springboot医院核酸检测预约挂号微信小程序(源码 + 数据库+LW+PPT)
- 基本复现-计及碳排放成本的电-气-热综合能源系统节点能价计算方法研究 真正做到了电热气潮流耦合,很适合综合能源系统建模的初学者,配合复现lunwen 运行程序HeatGasPowerCombinat
- C++新手教程(第三篇:iostream输出,输入流cin&cout)
- Python培训之美眉图片下载爬虫 04 提取某列表页内模特图片地址.flv
- comsol激光熔覆 热固流仿真 温度场?流场,有教学视频
- 永磁同步电机的SMO滑模观测器无传感器矢量控制算法,matlab,仿真,有资料
- 风光柴储 混合微电网 储能电池系统 互补能量管理 MATLAB simulink仿真 2018b及以上 完美运行
- vnc arm-linux版
- 表贴式永磁同步电机一阶线性 非线性自抗扰(ADRC)matlab simulink模型 ESO,扩张状态观测器 模型,带参考资料,文献
- Python培训之美眉图片下载爬虫 05 提取某列表页内模特个人网站地址.flv
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈