一:使用管理服务器和脚本
在试图菜单中选族已注册的服务器,可以直接切换登录服务器
在试图菜单中选择解决方案资源管理器,可以直接打开之前保存的脚本,方便管理和执行
这两种保存时,都可以分组保存,见下图
二:网络配置
mssqlserver的协议中可以改端口,比如改成端口1422,则登陆时,要在服务器后面加上",1422",如"127.0.0.1,1422"
见下图:
三:top(2) insert 和delete中应用
将stuAll表中的前两条数据插入到stu表中
insert top(2) into stu(id,name) select id,name from stuAll
只删除匹配的前两条数据
delete top(2) from stu
四:联结查询
内查询:inner join 即左右外联结的交集
外连接:outer join 包括left outer join 和right outer join
完全连接:full join 即左右外联结的并集
交叉连接:cross join 即笛卡尔积,若a表5行,b表6行,则结果有30行
五:联合
union :会去掉重复的行
union all:全部并入到结果中,包括重复行
六:更精确的时间
datetime2(n) 和time(n),其中n能从0到7
七:创建数据库
create database stu on ( name=stu_db, filename='d:\stu_db.mdf', size=10, maxsize=50, filegrowth=5 ) log on ( name=stu_log, filename='d:\stu_log.ldf', size=5, maxsize=25, filegrowth=5 )
size 表示初始大小,maxsize表示数据文件的最大值,filegrowth有两种,一种是按百分比,如filegrowth=10%,另一种是按大小,如filegrowth=5
修改数据库信息:
alter database stu
modify file
(
name=stu_db,
size=20
)
八:判断数据库是否存在
if exists(select * from sys.objects where object_id= OBJECT_ID('stu2') and type ='u')
drop table stu2;
注意:if exists(select * from sys.objects where object_id= OBJECT_ID('stu2'))
drop table stu2;
这个是错误的,必须得加上 and type ='u'