【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基础之索引
索引用于快速找出在某个列中有某一特定值的行,不使用索引,数据库必须从第一条记录开始读完整个表,直到找出相关的行.表越大,查询数据所花费的时间越多,如果表中查询的列有一个索引,数据库能快速到达一个位置 ...
随机推荐
- centos7安装使用docker-tomcat-mysql
windows安装centos虚拟机 下载安装 virtualBox下载 https://mirrors.tuna.tsinghua.edu.cn/help/virtualbox/ centos7镜像 ...
- Codeforces Round #506 (Div. 3) 1029 D. Concatenated Multiples
题意: 给定n个数字,和一个模数k,从中选出两个数,直接拼接,问拼接成的数字是k的倍数的组合有多少个. 思路: 对于a,b两个数,假定len = length of (b),那么a,b满足条件就是a ...
- CodeForces 715B Complete The Graph 特殊的dijkstra
Complete The Graph 题解: 比较特殊的dij的题目. dis[x][y] 代表的是用了x条特殊边, y点的距离是多少. 然后我们通过dij更新dis数组. 然后在跑的时候,把特殊边都 ...
- CF995B Suit and Tie 贪心 第十三
Suit and Tie time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...
- 「每日五分钟,玩转JVM」:对象内存布局
概览 一个对象根据不同情况可以被划分成两种情况,当对象是一个非数组对象的时候,对象头,实例数据,对齐填充在内存中三分天下,而数组对象中在对象头中多了一个用于描述数组对象长度的部分 对象头 对象头分为两 ...
- 【Offer】[13] 【机器人的运动范围】
题目描述 思路分析 Java代码 代码链接 题目描述 地上有一个m行和n列的方格.一个机器人从坐标0,0的格子开始移动,每一次只能向左,右,上,下四个方向移动一格,但是不能进入行坐标和列坐标的数位之和 ...
- Linux中新建用户用不了sudo命令问题:rootr is not in the sudoers file.This incident will be reported解决
参考:https://blog.csdn.net/lichangzai/article/details/39501025 如果执行sudo命令的用户没有执行sudo的权限,执行sudo命令时会报下面的 ...
- android中的菜单Menu
Menu是一个接口, 他有2个子接口, SubMenu和ContextMenu; 前者菜单常见于按home键就会出现 ,后者是一个上下文菜单, 一般点击某个条目会在手机屏幕中出现一个类似悬浮窗口的菜单 ...
- charles 设置为chrome代理
本文参考:charles 设置为chrome代理 将charles设置为chrome的代理 需要注意的是,Chrome 和 Firefox 浏览器并不一定使用的就是本机,可能是一些代理工具,而 Cha ...
- JDBC连接时出现的问题总结
java.sql.SQLException: The server time zone value '�й���ʱ��' is unrecognized or represents more tha ...