【SQL server基础】手动创建数据库和表格
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基础】手动创建数据库和表格的更多相关文章
- 【SQL server基础】判断数据库、表格、视图、存储过程、函数书否存在
库是否存在 if exists(select * from master..sysdatabases where name=N'库名') print 'exists' else print 'not ...
- 利用Microsoft Sql Server Management studio 创建数据库的示例
利用Microsoft Sql Server Management studio 创建数据库的示例方法如下: 一.打开安装好的Microsoft Sql Server Management stu ...
- 使用SQL Server Management Studio 创建数据库备份作业
--完整备份,每周一次USE MasterGOdeclare @str varchar(100)set @str='D:\Weldon\DBBACK\FullBak'+replace(replace( ...
- Sql Server——运用代码创建数据库及约束
在没有学习运用代码创建数据库.表和约束之前,我们只能用鼠标点击操作,这样看起来就不那么直观(高大上)了. 在写代码前要知道在哪里写和怎么运行: 点击新建查询,然后中间的白色空白地方就是写代码的地方了. ...
- 使用SQL Server Management Studio 创建作业备份数据库
在项目中,经常需要备份数据库,如果能做到只需点个按钮(“开始备份数据库”按钮),然后什么都不管,数据库就自动备份好了,或者服务器上的数据库隔一段时间自动备份一次,那该多好啊. Sql server 的 ...
- 数据库开发基础-SQl Server 基础
SQL Server 基础 1.什么是SQL Server SQL:Structured Query Language 结构化查询语言 SQL Server是一个以客户/服务器(c/s)模式访问.使 ...
- Sql Server来龙去脉系列之四 数据库和文件
在讨论数据库之前我们先要明白一个问题:什么是数据库? 数据库是若干对象的集合,这些对象用来控制和维护数据.一个经典的数据库实例仅仅包含少量的数据库,但用户一般也不会在一个实例上创建太多 ...
- 【SQL server基础】objectproperty()函数
SQL Server OBJECTPROPERTY使用方法 OBJECTPROPERTY 返回有关当前数据库中的模式作用域对象的信息.此函数不能用于不是模式范围的对象,例如数据定义语言(DDL)触 ...
- SQL Server基础之索引
索引用于快速找出在某个列中有某一特定值的行,不使用索引,数据库必须从第一条记录开始读完整个表,直到找出相关的行.表越大,查询数据所花费的时间越多,如果表中查询的列有一个索引,数据库能快速到达一个位置 ...
随机推荐
- 技术改变生活| 免费看VIP视频,屏蔽广告,解锁新姿势!
说到这个,我就忍不住的要介绍一下今天的主角 Tampermonkey 了.Tampermonkey 是一款免费的浏览器扩展和最为流行的用户脚本管理器,它适用于Chrome, Microsoft Edg ...
- UVA P12101 【Prime Path】
题库 :UVA 题号 :12101 题目 :Prime Path link :https://www.luogu.org/problemnew/show/UVA12101
- SQlServer 数据库表名称,字段比较
项目中一般分测试环境(QAS),生产环境(PRD),当我们的项目经历了一次周期跨度较长的更新后,当我们发布到生产环境时,首要的任务是将新增的表,字段更新到生产数据库.很多时候,当我们发布更新的时候,已 ...
- CodeForces - 697D - Puzzles DFS
传送门:D - Puzzles 题意:在一个图中,从1开始dfs,求每一个点到达的期望: 思路:(下面是队长写的) 首先求的是到每一个点的步数的期望. 记fa( u ) = v, son( v )表示 ...
- CF980C Posterized 贪心 二十五
Posterized time limit per test 1 second memory limit per test 256 megabytes input standard input out ...
- 【Mac】快速复制文件路径
一.使用Automator新建服务 二.配置 三.使用 四.创建快捷键 一.使用Automator新建服务 在应用程序文件夹里打开Automator,选择文件菜单,新建一个服务,如下  二.配置 在 ...
- 【Offer】[16] 【数值的整数次方】
题目描述 思路分析 测试用例 Java代码 代码链接 题目描述 实现函数double Power(double base, int exponent),求base的exponent次方.不得使用库函数 ...
- 【LeetCode】5# 最长回文子串
题目描述 给定一个字符串 s,找到 s 中最长的回文子串.你可以假设 s 的最大长度为 1000. 示例 1: 输入: "babad" 输出: "bab" 注意 ...
- Web框架之Gin
Gin是一个用Go语言编写的web框架.它是一个类似于martini但拥有更好性能的API框架, 由于使用了httprouter,速度提高了近40倍. 如果你是性能和高效的追求者, 你会爱上Gin. ...
- Maven学习归纳(三)——依赖添加依赖排除与项目整合
一.Maven的坐标 1. 坐标的定义 数学意义上的坐标可以是平面上的(x,y)也可以是空间上的(x,y,z),都可以确定一个质点的位置和方向. Maven中有很多构件,为了能够自动化解析任何一个构件 ...