use master
go
if exists(select * from sysdatabases where name='learning')
drop database learning
go
CREATE DATABASE learning
ON
( NAME='learning_data', --主数据文件的逻辑名称
FILENAME='E:\SQLlearning\learning.mdf', -- 主数据文件的物理名称
SIZE=10MB, --主数据文件的初始大小
MAXSIZE=50MB, -- 主数据文件增长的最大值
FILEGROWTH=% --主数据文件的增长率
)
--/*--日志文件的具体描述,各参数含义同上--*/
LOG ON(
NAME='learning_log',
FILENAME='E:\SQLlearning\learning.ldf',
SIZE=5MB,
MAXSIZE=25MB,
FILEGROWTH=5MB)
GO USE learning
GO
--在视图sysobjects中查找是否存在userInfo表格
if exists(select * from dbo.sysobjects where name='userInfo')
drop table userInfo
GO
--用户信息表格
create table userInfo
(
userId int not null, --自增长ID
userName varchar() not null, --用户姓名
password varchar() not null, --用户密码
email varchar() not null, --用户邮箱
userRole int, --用户角色(:普通会员,1管理员)
registerDate varchar() --注册时间(默认当前时间)
)
--员工信息表格
if exists(select * from sysobjects where name='employInfo')
drop table employInfo
GO
create table employInfo
(
employId int not null, --自增长ID
employNumber varchar() not null, --员工编号
employPassword varchar() not null, --员工密码(默认6个8)
employRealName varchar() not null, --员工真实姓名
employPhoneNum varchar() not null --员工联系电话 ) --员工业绩表格
if exists(select * from dbo.sysobjects where name='employResult')
drop table employResult
GO
create table employResult
(
employResultId int not null, --自增长ID
employResultNum varchar() not null, --业绩编号
employNumber varchar() not null, --员工编号
houseNumber varchar() not null, --房屋编号
houseAmount float, --房屋售价/出租价
percentPaid float, --提成比例(%提成)
salesCompleted varchar(), --销售完成时间
) --房屋信息表格
if exists(select * from dbo.sysobjects where name='houseInfo')
drop table houseInfo
GO
create table houseInfo(
houseId int not null, --自增长ID
houseNumber varchar() not null, --房屋编号
userName varchar() not null, --房屋发布会员
employNumber varchar() not null, --房屋对应负责销售员工编号(唯一主键)
informationType int not null, --判断是发布出租/出售房屋类型(0代表发布出租信息,1代表发布出售信息)
houseOwnerName varchar() not null, --业主姓名
houseOwnerSex int not null, --业主性别(:代表男,:代表女)
houseOwnerPhoneNumber varchar(), --联系电话
houseArea varchar() not null, --房屋所在区域
houseSize int not null, --房屋面积
houseFloor int, --房屋出租/出售 楼层
houseTotalFloor int, --房屋总楼层数
HouseUnit varchar(), --房屋户型(一室一厅,二室一厅,)[数据存储值为:一室二厅]
BudgetPrice float, --预算价格
SpecificAddress varchar() not null, --房屋具体地址
houseFloorType int not null, --楼型,,[:代表高层,:代表多层,:平房,:其他]
otherRequirements varchar() --其他信息
) --房产资讯表格 if exists(select * from dbo.sysobjects where name='houseNews')
drop table houseNews
GO
create table houseNews(
houseNewId int not null, --自增长ID
houseNewTheme varchar() not null, --咨询主题
houseNewContent text, --咨询内容
houseNewDate varchar() --发布日期
) --留言评论表
if exists(select * from dbo.sysobjects where name='Message')
drop table Message
GO
create table Message(
messageId int not null, --自增长ID
houseNumber varchar() not null, --房屋出租/出售编号(针对房屋编号留言)
messageContent varchar() not null, --留言内容
contact varchar(), --联系方式
messageDate varchar() not null --留言时间
) --添加约束
alter table userInfo add constraint pk_userId primary key(userId);
alter table userInfo add constraint DF_userRole default()for userRole;
alter table userInfo add constraint DF_registerDate default(CONVERT(varchar(),GETDATE(),)) for registerDate; alter table houseInfo add constraint pk_houseId primary key(houseId); alter table employInfo add constraint pk_employInfo primary key(employId);
alter table employInfo add constraint DF_employPassword default('')for employPassword; alter table employResult add constraint pk_employResult primary key(employResultId); alter table houseNews add constraint pk_houseNewId primary key(houseNewId);
alter table houseNews add constraint DF_houseNewDate default(CONVERT(varchar(),GETDATE(),)) for houseNewDate; alter table T_Message add constraint pk_messageId primary key(messageId);
alter table T_Message add constraint DF_messageDate default(CONVERT(varchar(),GETDATE(),))for messageDate; GO

【SQL server基础】手动创建数据库和表格的更多相关文章

  1. 【SQL server基础】判断数据库、表格、视图、存储过程、函数书否存在

    库是否存在 if exists(select * from master..sysdatabases where name=N'库名') print 'exists' else print 'not ...

  2. 利用Microsoft Sql Server Management studio 创建数据库的示例

    利用Microsoft Sql Server Management studio 创建数据库的示例方法如下:   一.打开安装好的Microsoft Sql Server Management stu ...

  3. 使用SQL Server Management Studio 创建数据库备份作业

    --完整备份,每周一次USE MasterGOdeclare @str varchar(100)set @str='D:\Weldon\DBBACK\FullBak'+replace(replace( ...

  4. Sql Server——运用代码创建数据库及约束

    在没有学习运用代码创建数据库.表和约束之前,我们只能用鼠标点击操作,这样看起来就不那么直观(高大上)了. 在写代码前要知道在哪里写和怎么运行: 点击新建查询,然后中间的白色空白地方就是写代码的地方了. ...

  5. 使用SQL Server Management Studio 创建作业备份数据库

    在项目中,经常需要备份数据库,如果能做到只需点个按钮(“开始备份数据库”按钮),然后什么都不管,数据库就自动备份好了,或者服务器上的数据库隔一段时间自动备份一次,那该多好啊. Sql server 的 ...

  6. 数据库开发基础-SQl Server 基础

    SQL Server 基础 1.什么是SQL Server SQL:Structured Query Language  结构化查询语言 SQL Server是一个以客户/服务器(c/s)模式访问.使 ...

  7. Sql Server来龙去脉系列之四 数据库和文件

        在讨论数据库之前我们先要明白一个问题:什么是数据库?     数据库是若干对象的集合,这些对象用来控制和维护数据.一个经典的数据库实例仅仅包含少量的数据库,但用户一般也不会在一个实例上创建太多 ...

  8. 【SQL server基础】objectproperty()函数

    SQL Server OBJECTPROPERTY使用方法   OBJECTPROPERTY 返回有关当前数据库中的模式作用域对象的信息.此函数不能用于不是模式范围的对象,例如数据定义语言(DDL)触 ...

  9. SQL Server基础之索引

     索引用于快速找出在某个列中有某一特定值的行,不使用索引,数据库必须从第一条记录开始读完整个表,直到找出相关的行.表越大,查询数据所花费的时间越多,如果表中查询的列有一个索引,数据库能快速到达一个位置 ...

随机推荐

  1. 【凭据不工作】Win远程桌面提示您的凭据不工作

    1.浏览器直接进入云服务器 2.打开运行 --输入gpedit.msc--计算机配置--管理模板--windows组件--远程桌面服务--远程桌面会话主机--安全--远程(RDP)链接要求使用制定的安 ...

  2. ThreadPoolExecutor执行任务,异常日志缺失问题

    之前在使用自定义线程池异步执行耗时任务时,一直记着如果业务方法抛出异常没有捕获,那么是看不到日志框架输出的异常日志的,所以总是在业务方法中包裹一层try-catch捕获可能发生的异常.也未去深入为什么 ...

  3. P1640 [SCOI2010]连续攻击游戏 二分图构造

    https://www.luogu.org/problemnew/show/P1640 题意 lxhgww最近迷上了一款游戏,在游戏里,他拥有很多的装备,每种装备都有2个属性,这些属性的值用[1,10 ...

  4. 2019 Multi-University Training Contest 1

    2019 Multi-University Training Contest 1 A. Blank upsolved by F0_0H 题意 给序列染色,使得 \([l_i,r_i]\) 区间内恰出现 ...

  5. CodeForces 367 C Sereja and the Arrangement of Numbers 欧拉回路

    Sereja and the Arrangement of Numbers 题解: ummm. 在一副图中,如果全部点的度数是偶数/只有2个点是奇数,则能一笔画. 考虑图的点数k为奇数的时候,那么每个 ...

  6. ZOJ-1610 Count the Colors ( 线段树 )

    题目链接: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1610 Description Painting some co ...

  7. CCPC-Wannafly Summer Camp #1(部分解题报告)

    A:Birthday 时间限制: 1 Sec  内存限制: 256 MB 题目描述 恬恬的生日临近了.宇扬给她准备了一个大蛋糕. 正如往常一样,宇扬在蛋糕上插了n支蜡烛,并把蛋糕分为m个区域.因为某种 ...

  8. 【Offer】[53-3] 【数组中数值和下标相等的元素】

    题目描述 思路分析 测试用例 Java代码 代码链接 题目描述 假设一个单调递增的数组里的每个元素都是整数并且是唯一的.请编程实现一个函数,找出数组中任意一个数值等于其下标的元素.例如,在数组{-3, ...

  9. 题解 洛谷P5259【欧稳欧再次学车】

    实际上没什么可说的,暴力大模拟就好. 一定要开long long! 一定要开long long! 一定要开long long! (不然会炸数据的!!!) //Stand up for the fait ...

  10. CXF添加拦截器和自定义拦截器

    前面讲了如何采用CXF开发webservice,现在来讲如何添加拦截器和自定义拦截器. 服务端代码: HelloWorld implementor=new HelloWorldImpl(); Stri ...