博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
创建租房网House脚本
阅读量:6828 次
发布时间:2019-06-26

本文共 6286 字,大约阅读时间需要 20 分钟。

USE MASTER GOEXEC XP_CMDSHELL 'MKDIR E:\HOUSE1'GOSET NOCOUNT ON----不显示影响行数IF EXISTS(SELECT * FROM SYS.DATABASES WHERE NAME='HOUSE')DROP DATABASE HOUSEGO----创建数据库HOUSECREATE DATABASE HOUSEON(NAME='HOUSE_DATA',FILENAME='E:\HOUSE1\HOUSE_DATA.MDF',SIZE=3,FILEGROWTH=1)LOG ON(NAME='HOUSE_LOG',FILENAME='E:\HOUSE1\HOUSE_DATA.LDF',SIZE=10,FILEGROWTH=10%)GO/*------创建表-----------*/--------建表:sys_user(用户信息表)USE HOUSEGOIF EXISTS(SELECT * FROM SYS.OBJECTS WHERE NAME='sys_user')DROP TABLE sys_userGOCREATE TABLE sys_user(UID INT IDENTITY (1,1) NOT NULL,---用户编号UNAME VARCHAR(20) NOT NULL ,---姓名UPASSWORD VARCHAR(20) NOT NULL---密码)GO------建表sys_user的约束ALTER TABLE sys_userADD CONSTRAINT PK_UID PRIMARY KEY (UID),    CONSTRAINT CK_UPASSWORD CHECK(LEN(UPASSWORD)>6)GO-----建表hos_districtIF EXISTS( SELECT * FROM SYS.OBJECTS WHERE NAME='hos_district')DROP TABLE hos_district GOCREATE TABLE hos_district(DID INT IDENTITY (1,1) PRIMARY KEY NOT NULL ,---区县编号(主键)DNAME VARCHAR(20) NOT NULL ----区县名称)GO----建表hos_streetIF EXISTS (SELECT * FROM SYS.OBJECTS WHERE NAME='hos_street')DROP TABLE hos_streetGOCREATE TABLE hos_street(SID INT IDENTITY(1,1) PRIMARY KEY  NOT NULL,---街道编号(主键)SNAME VARCHAR(100) NOT NULL,---街道名称SDID INT FOREIGN KEY (SDID)  REFERENCES hos_district (DID) NOT NULL )GO-----建表hos_typeIF EXISTS (SELECT * FROM SYS.OBJECTS WHERE NAME='hos_type')DROP TABLE hos_typeGOCREATE TABLE hos_type(HTID INT IDENTITY(1,1) PRIMARY KEY NOT NULL,----房屋类型编号(主键)HTNAME VARCHAR(20) NOT NULL ---房屋类型)GO-----建表:hos_houseIF EXISTS(SELECT * FROM SYS.OBJECTS WHERE NAME='hos_house')DROP TABLE hos_houseGOCREATE TABLE hos_house(HMID INT IDENTITY(1,1) NOT NULL,---(房屋信息编号)UID INT NOT NULL,----用户编号--DID INT NOT NULL,----区县编号SID INT NOT NULL,----街道编号HTID INT NOT NULL,---房屋类型编号PRICE  DECIMAL(18,2) NOT NULL,--价格TOPIC VARCHAR(20) NOT NULL,---标题CONTENTS VARCHAR(100) NOT NULL,---描述HTIME DATETIME NOT NULL,---发布时间COPY VARCHAR(20) ---备注)GO-----添加约束(house)ALTER TABLE hos_houseADD CONSTRAINT PK_HMID PRIMARY KEY (HMID),    CONSTRAINT DF_PRICE DEFAULT(0) FOR PRICE,    CONSTRAINT CK_PRICE CHECK(PRICE>0),    CONSTRAINT DF_HTIME DEFAULT(GETDATE()) FOR HTIME,    CONSTRAINT CK_HTIME CHECK(HTIME<=GETDATE()),    CONSTRAINT FK_UID FOREIGN KEY (UID) REFERENCES sys_user(UID) ,   -- CONSTRAINT FK_DID FOREIGN KEY (DID) REFERENCES hos_district(DID),    CONSTRAINT FK_SID FOREIGN KEY (SID) REFERENCES hos_street (SID),    CONSTRAINT FK_HTID FOREIGN KEY(HTID) REFERENCES hos_type(HTID)GO--------添加测试数据-----sys_user插入数据INSERT INTO sys_user(UNAME,UPASSWORD) VALUES('张三','s217701')INSERT INTO sys_user(UNAME,UPASSWORD) VALUES('李四','s217702')INSERT INTO sys_user(UNAME,UPASSWORD) VALUES('王鑫','s217703')INSERT INTO sys_user(UNAME,UPASSWORD) VALUES('张建','s217704')INSERT INTO sys_user(UNAME,UPASSWORD) VALUES('李剑','s217705')INSERT INTO sys_user(UNAME,UPASSWORD) VALUES('蒋以然','s217706')INSERT INTO sys_user(UNAME,UPASSWORD) VALUES('王晓超','s217707')INSERT INTO sys_user(UNAME,UPASSWORD) VALUES('张冬雪','s217708')INSERT INTO sys_user(UNAME,UPASSWORD) VALUES('孙鹏','s217709')INSERT INTO sys_user(UNAME,UPASSWORD) VALUES('蒋连昌','s217710')GO-----表hos_district插入数据INSERT INTO hos_district (DNAME) VALUES('海淀区')INSERT INTO hos_district (DNAME) VALUES('西城区')INSERT INTO hos_district (DNAME) VALUES('东城区')INSERT INTO hos_district (DNAME) VALUES('朝阳区')INSERT INTO hos_district (DNAME) VALUES('景山区')INSERT INTO hos_district (DNAME) VALUES('宣武区')INSERT INTO hos_district (DNAME) VALUES('大兴')INSERT INTO hos_district (DNAME) VALUES('丰台')GO----表hos_street插入数据INSERT INTO hos_street (SNAME,SDID) VALUES('中关村',1)INSERT INTO hos_street (SNAME,SDID) VALUES('苏州街',1)INSERT INTO hos_street (SNAME,SDID) VALUES('万泉庄',1)INSERT INTO hos_street (SNAME,SDID) VALUES('东四',3)INSERT INTO hos_street (SNAME,SDID) VALUES('东单',3)INSERT INTO hos_street (SNAME,SDID) VALUES('西四',2)INSERT INTO hos_street (SNAME,SDID) VALUES('西单',2)INSERT INTO hos_street (SNAME,SDID) VALUES('东湖',4)INSERT INTO hos_street (SNAME,SDID) VALUES('八里庄',4)INSERT INTO hos_street (SNAME,SDID) VALUES('双井',5)INSERT INTO hos_street (SNAME,SDID) VALUES('陶然亭',5)INSERT INTO hos_street (SNAME,SDID) VALUES('南菜园',6)INSERT INTO hos_street (SNAME,SDID) VALUES('兴丰街',7)INSERT INTO hos_street (SNAME,SDID) VALUES('黄村',7)INSERT INTO hos_street (SNAME,SDID) VALUES('南苑街',8)INSERT INTO hos_street (SNAME,SDID) VALUES('东铁营',8)GO-----表hos_type插入数据INSERT INTO hos_type (HTNAME) VALUES('一室一卫')INSERT INTO hos_type (HTNAME) VALUES('一室一厅')INSERT INTO hos_type (HTNAME) VALUES('两室一卫')INSERT INTO hos_type (HTNAME) VALUES('两室一厅')INSERT INTO hos_type (HTNAME) VALUES('三室一厅')INSERT INTO hos_type (HTNAME) VALUES('三室两厅')GO----表hos_house插入数据INSERT INTO hos_house(UID,SID,HTID,PRICE,TOPIC,CONTENTS,HTIME,COPY)VALUES(1,1,2,2600,'中关村','中关村一条街','2009-1-2','中关村')INSERT INTO hos_house(UID,SID,HTID,PRICE,TOPIC,CONTENTS,HTIME,COPY)VALUES(2,2,3,3600,'苏州街','苏州街一条街','2009-1-3','苏州街')INSERT INTO hos_house(UID,SID,HTID,PRICE,TOPIC,CONTENTS,HTIME,COPY)VALUES(3,3,4,4600,'万泉庄','万泉庄一条街','2009-1-4','万泉庄')INSERT INTO hos_house(UID,SID,HTID,PRICE,TOPIC,CONTENTS,HTIME,COPY)VALUES(1,3,2,1500,'万泉庄附近','万泉庄附近一条街','2009-7-2','万泉庄附近')INSERT INTO hos_house(UID,SID,HTID,PRICE,TOPIC,CONTENTS,HTIME,COPY)VALUES(1,5,2,2700,'东单','东单很多美食','2009-9-2','东单')INSERT INTO hos_house(UID,SID,HTID,PRICE,TOPIC,CONTENTS,HTIME,COPY)VALUES(3,1,2,2600,'中关村','中关村电脑城','2009-4-1','中关村')INSERT INTO hos_house(UID,SID,HTID,PRICE,TOPIC,CONTENTS,HTIME,COPY)VALUES(4,4,1,2000,'东四','东四一条街','2009-4-2','东四')INSERT INTO hos_house(UID,SID,HTID,PRICE,TOPIC,CONTENTS,HTIME,COPY)VALUES(5,6,3,3600,'西四','西四一条街','2009-1-2','西四')INSERT INTO hos_house(UID,SID,HTID,PRICE,TOPIC,CONTENTS,HTIME,COPY)VALUES(5,7,2,3600,'西单','西单购物城','2009-4-2','西单')INSERT INTO hos_house(UID,SID,HTID,PRICE,TOPIC,CONTENTS,HTIME,COPY)VALUES(6,2,2,2600,'苏州街','苏州街美食','2009-2-2','苏州街')INSERT INTO hos_house(UID,SID,HTID,PRICE,TOPIC,CONTENTS,HTIME,COPY)VALUES(7,8,3,2900,'朝阳东湖','朝阳东湖一景','2009-3-2','朝阳')INSERT INTO hos_house(UID,SID,HTID,PRICE,TOPIC,CONTENTS,HTIME,COPY)VALUES(8,3,1,700,'万泉庄','万泉庄一条街','2009-5-2','万泉庄')INSERT INTO hos_house(UID,SID,HTID,PRICE,TOPIC,CONTENTS,HTIME,COPY)VALUES(3,2,3,4200,'苏州街','苏州街二条街','2009-1-3','苏州街')INSERT INTO hos_house(UID,SID,HTID,PRICE,TOPIC,CONTENTS,HTIME,COPY)VALUES(4,2,3,4100,'苏州街','苏州街西街','2009-1-3','苏州街')GO

 

转载于:https://www.cnblogs.com/WuXuanKun/p/5280939.html

你可能感兴趣的文章
ADC In An FPGA
查看>>
Linux ftp 命令
查看>>
EntityFramework:状态变化与方法的关系
查看>>
Dalvik虚拟机简要介绍和学习计划
查看>>
危险的浮点数float
查看>>
Test class should have exactly one public zero-argument constructor
查看>>
学习笔记之编译和链接
查看>>
百度网页搜索部
查看>>
Flex与SSH集成
查看>>
LifecyclePhaseNotFoundException(转)
查看>>
android 5.0
查看>>
探索Android中的Parcel机制(上)
查看>>
Oracle Minus 取差集
查看>>
下载Google官方/CM Android源代码自动重新开始的Shell脚本
查看>>
python操作Excel读--使用xlrd
查看>>
HTML一(简介)
查看>>
#import &lt;/usr/include/objc/objc-class.h&gt; not such file or directory问题的解决方法
查看>>
集装箱项目
查看>>
C#中的Action<>和Func<>
查看>>
关于opencv中人脸识别主函数的部分注释详解。
查看>>