sql中如果存在数据库或表则删除数据库或表
--房屋发布系统--注意:使用该sql语句生成数据库和表时,必须先在E盘下创建名为houseRental 的文件夹;USE masterGOif exists(select * from dbo.sysdatabases where name='houseRental')drop database houseRentalGOCREATE DATABASE houseRentalON ( NAME = 'houseRental_data', FILENAME = 'E:\houseRental\houseRental.mdf', SIZE = 10, MAXSIZE = 50, FILEGROWTH = 5 )LOG ON( NAME = 'houseRental_log',FILENAME = 'E:\houseRental\houseRental.ldf',SIZE = 5MB,MAXSIZE = 25MB,FILEGROWTH = 5MB )GOUSE houseRentalGO--用户信息表;if exists(select * from dbo.sysobjects where name='userInfo')drop table userInfoGOcreate table userInfo(userId int not null,--自增长IDuserName varchar(15) not null,--用户名,唯一性password varchar(15) not null,--用户密码email varchar(25) not null,--邮箱地址userRole int,--默认为普通会员(0:默认为普通会员,1:为管理员)registDate varchar(25)--默认当前时间)--房屋信息表;if exists(select * from dbo.sysobjects where name='houseInfo')drop table houseInfoGOcreate table houseInfo(houseId int not null,--自增长IDhouseNumbervarchar(15) not null,--房屋编号userNamevarchar(15) not null,--房屋发布会员employNumbervarchar(15) not null,--房屋对应负责销售员工编号(唯一主键)informationType int not null,--判断是发布出租/出售房屋类型(0代表发布出租信息,1代表发布出售信息)houseOwnerName varchar(15) not null, --业主姓名houseOwnerSex int not null,--业主性别(0:代表男,1:代表女)houseOwnerPhoneNumber varchar(15), --联系电话houseArea varchar(15) not null,--房屋所在区域houseSize int not null,--房屋面积houseFloor int,--房屋出租/出售 楼层houseTotalFloor int, --房屋总楼层数HouseUnitvarchar(15), --房屋户型(一室一厅,二室一厅,)[数据存储值为:一室二厅]BudgetPrice float, --预算价格SpecificAddress varchar(200) not null,--房屋具体地址houseFloorType int not null,--楼型,,[0:代表高层,1:代表多层,2:平房,3:其他]otherRequirements varchar(200)--其他信息)--员工信息表;if exists(select * from dbo.sysobjects where name='employInfo')drop table employInfoGOcreate table employInfo(employId int not null,--自增长IDemployNumber varchar(15) not null,--员工编号employPassWordvarchar(15) not null,--员工密码,默认为6个8;employRealNamevarchar(15) not null,--员工真实姓名employPhoneNumbervarchar(15) not null--员工联系电话)--员工业绩表;if exists(select * from dbo.sysobjects where name='employResult')drop table employResultGOcreate table employResult(employResultIdint not null,--自增长IDemployResultNumbervarchar(15) not null,--业绩编号employNumbervarchar(15) not null,--员工编号houseNumbervarchar(15) not null,--房屋编号houseAmountfloat,--房屋售价/出租价percentPaidfloat,--销售提成比例(按总金额的20%拿提成)salesCompletedvarchar(15)--销售完成时间)--房产咨询表;if exists(select * from dbo.sysobjects where name='houseNews')drop table houseNewsGOcreate table houseNews(houseNewIdint not null,--自增长IDhouseNewThemevarchar(200) not null,--咨询主题houseNewContenttext,--咨询内容houseNewDatevarchar(15)--发布日期)--留言评论表if exists(select * from dbo.sysobjects where name='Message')drop table MessageGOcreate table Message(messageIdint not null,--自增长IDhouseNumbervarchar(15) not null,--房屋出租/出售编号(针对房屋编号留言)messageContentvarchar(200) not null,--留言内容contactvarchar(50),--联系方式messageDatevarchar(15) not null--留言时间)--添加约束alter table userInfo add constraint pk_userId primary key (userId);alter table userInfo add constraint DF_userRole default(0) for userRole;alter table userInfo add constraint DF_registDate default(CONVERT(varchar(100), GETDATE(), 23)) for registDate;alter table houseInfo add constraint pk_houseId primary key (houseId);alter table employInfo add constraint pk_employId primary key (employId);alter table employInfo add constraint DF_employPassWord default('888888') for employPassWord;alter table employResult add constraint pk_employResultId primary key (employResultId);alter table houseNews add constraint pk_houseNewId primary key (houseNewId);alter table houseNews add constraint DF_houseNewDate default(CONVERT(varchar(100), GETDATE(), 23)) for houseNewDate;alter table Message add constraint pk_messageId primary key (messageId);alter table Message add constraint DF_messageDate default(CONVERT(varchar(100), GETDATE(), 23)) for messageDate;