你所需要的sql数据库资料
什么时候需要加,:
if exists(select * from sysdatabases where name='TestSchool')
drop database TestSchool
go
自动创建文件夹
exec sp_configure 'show advanced options',
go
RECONFIGURE
go
exec sp_configure 'xp_cmdshell',
go
RECONFIGURE
go
exec xp_cmdshell 'mkdir d:\qqaa\vv\cc' create database TestSchool
on primary
(
name='TestSchool_data',逻辑名称
size=3MB, 初始大小
FileGrowth=%,每次增长按总大小的10%增长
maxSize=1000mb,最大容量
FileName='d:\qqaa\vv\cc\TestSchool_data.mdf'
),
(
name='TestSchool_data1',逻辑名称
size=3MB, 初始大小
FileGrowth=%,每次增长按总大小的10%增长
maxSize=1000mb,最大容量
FileName='d:\project\TestSchool_data1.ndf'
)
log on
(
name='TestSchool_log',逻辑名称
size=3MB, 初始大小
FileGrowth=%,每次增长按总大小的10%增长
maxSize=1000mb,最大容量
FileName='d:\qqaa\vv\cc\TestSchool_log.ldf'
),
(
name='TestSchool_log1',逻辑名称
size=3MB, 初始大小
FileGrowth=%,每次增长按总大小的10%增长
maxSize=1000mb,最大容量
FileName='d:\qqaa\vv\cc\TestSchool_log1.ldf'
)
use TestSchool
go
if exists(select * from sysobjects where name='Teacher')
drop table Teacher
go
create table Teacher
(
Id int primary key identity(,), 主键是非空唯一
Name nvarchar() not null, not null不为空
Gender bit not null default() ,
Age int not null check(age> and age<=),
Salary money, 可以为null可以写null,或者不写也默认是可以为null
Birthday datetime not null
)
约束-保证数据完整性
if exists(select * from sysobjects where name='PK_id')
alter table teacher drop constraint PK_id
alter table teacher
add constraint PK_id primary key(id)
alter table teaher
add constraint UQ_name unique(name)
alter table teacher
add constraint DF_Birthday default('1999-9-9') for birthday
alter table teacher with nocheck 不检查现有数据
add constraint FK_teacher_subjectId foreign key(subjectid) references subject(id)
on delete no action
Len():得到当前指定字符串的个数,中英文无关
select LEN('abcdefg')
select DataLength('中华人民共和国')
select LEN(Char) from chartest
select DataLength(Char) from chartest
select LEN(VarChar) from chartest
select DataLength(VarChar) from chartest
select LEN(NChar) from chartest
select DataLength(NChar) from chartest
select LEN(NVarChar) from chartest
select DataLength(NVarChar) from chartest
insert into Student values('','张三','男',,'',N'广州','1990-1-1','aa@bb.com')
insert into Student values('','张三','男',,null,'广州','1990-1-1',default)
insert into Student(LoginPwd,StudentName,Gender,GradeId,Birthday) values('','张三','男',,'1990-1-1')
INSERT 语句中列的数目小于 VALUES 子句中指定的值的数目。VALUES 子句中值的数目必须与 INSERT 语句中指定的列的数目匹配
insert into Student(LoginPwd,StudentName,Gender,GradeId) values('','张三','男',)
insert into Student(LoginPwd,StudentName,Gender,GradeId,Birthday) values('','张三','男',,'1999-9-9')
insert into Student(LoginPwd,StudentName,Gender,GradeId,Birthday) values('','张三',男,'','1999-9-9')
insert into Student(LoginPwd,StudentName,Gender,GradeId,Birthday) values('','张三','男','',--)
update Student set Gender='男' where StudentNo=
update Student set Phone= where StudentName='qq' and Gender='男'
update Student set LoginPwd='aaaaaa' ,Gender='男',GradeId=,Address='东莞' where StudentNo=
update Student set Birthday+=
update Student set Phone='' where Phone is null
update Student set Address=DEFAULT where StudentNo=
update Student set Phone='NULL' where StudentNo= update Student set Address='我在广州' where Address=default
delete from Student where Gender='男'
delete from Student
truncate table student
select * from Student where Sex='女' and StudentName like '林%'
select * from Student where Sex='女' and StudentName like '林__'
select * from Student where StudentNo in (,,,)
select * from Student where StudentNo like '[11-14]'
select StudentNo,StudentName,ISNULL(Email,'没有填写') from Student
select * from Student order by sex desc,StudentNo desc
select ClassId, COUNT(*) num from Student group by ClassId order by num desc select top ClassId, COUNT(*) num from Student group by ClassId order by num desc
select ClassId, SUM(ClassHour) from Subject where ClassId is not null group by ClassId select StudentNo,AVG(StudentResult) from Result group by StudentNo select SubjectId,AVG(StudentResult) from Result group by SubjectId
查询所有学员信息
select * from Student
指定查询的列
select StudentNo,StudentName,Gender,Address from Student
指定查询的列及查询的条件
select StudentNo,StudentName,Gender,Address from Student where Gender='女' and Address='广州'
设置虚拟结果集中的列名
select StudentNo as 学号,StudentName 姓名,性别=Gender,Address from Student where Gender='女' and Address='广州'
添加常量列
select StudentNo as 学号,StudentName 姓名,性别=Gender,Address, 国籍='中国' from Student where Gender='女' and Address='广州'
select top percent StudentNo as 学号,StudentName 姓名,性别=sex,Address from Student order by StudentName
select distinct 性别=sex,Address from Student select distinct sex from Student
select COUNT(sex) from Student
select MAX(BornDate) from Student
select min(BornDate) from Student
select MAX(sex) from Student nv
select min(sex) from Studentnan
select MAX(StudentResult) from Result
select MIN(StudentResult) from Result select sum(StudentResult) from Result where StudentNo=
select avg(StudentResult) from Result where StudentNo=
select sum(BornDate) from Student where StudentNo=
select avg(BornDate) from Student where StudentNo=
select sum(StudentName) from Student where StudentNo=
select avg(StudentName) from Student where StudentNo=
你所需要的sql数据库资料的更多相关文章
- 你所不知道的SQL Server数据库启动过程,以及启动不起来的各种问题的分析及解决技巧
目前SQL Server数据库作为微软一款优秀的RDBMS,其本身启动的时候是很少出问题的,我们在平时用的时候,很少关注起启动过程,或者很少了解其底层运行过程,大部分的过程只关注其内部的表.存储过程. ...
- 你所不知道的SQL Server数据库启动过程(用户数据库加载过程的疑难杂症)
前言 本篇主要是上一篇文章的补充篇,上一篇我们介绍了SQL Server服务启动过程所遇到的一些问题和解决方法,可点击查看,我们此篇主要介绍的是SQL Server启动过程中关于用户数据库加载的流程, ...
- 收缩SQL数据库日志
各位同学,相信大家在使用SQL数据库时,常常会遇到日志文件比数据库文件还在大的情况.以下有一简单的办法,可以快速的删除日志档.使用其大小变为540K. 供各位参考. DUMP TRANSACTION ...
- 收缩SQL数据库日志文件
收缩SQL数据库日志文件 介绍具体的操作方法前,先说下我操作的实际环境和当时的状况.我的服务器是windows server 2008 R2 64位英文版,数据库是SQL server 2008英文版 ...
- sql 数据库的备份还原问题
今天工作中犯了一个严重的错误,就是在sql中写了一个update语句,还没写条件呢,结果误按了F5,唉,太佩服自己啦...这个脑子怎么不管用了呢?? 唉不说了,我在网上翻来覆去的找资料,最终想是不是可 ...
- sql数据库的备份还原问题
sql数据库的备份还原问题 今天工作中犯了一个严重的错误,就是在sql中写了一个update语句,还没写条件呢,结果误按了F5,唉,太佩服自己啦...这个脑子怎么不管用了呢?? 唉不说了,我在网上翻来 ...
- 修改SQL数据库中表字段类型时,报“一个或多个对象访问此列”错误的解决方法
在SQL数据库中使用SQL语句(格式:alter table [tablename] alter column [colname] [newDataType])修改某表的字段类型时,报一下错误:由于一 ...
- C++操作 SQL数据库 实例 代码步骤
C++连接SQL数据库第一步 系统配置 1.设置SQLSERVER服务器为SQL登录方式,并且系统安全性中的sa用户要设置登录功能为“启用”,还有必须要有密码. 2.需要在ODBC中进行数据源配置,数 ...
- PostgreSQL数据库资料(转)
PostgreSQL数据库资料 转自:http://blog.csdn.net/postgrechina/article/details/49132791 推荐书籍: 概念书籍: <Postgr ...
随机推荐
- “全栈2019”Java第一百一十章:局部内部类与匿名内部类区别详解
难度 初级 学习时间 10分钟 适合人群 零基础 开发语言 Java 开发环境 JDK v11 IntelliJ IDEA v2018.3 文章原文链接 "全栈2019"Java第 ...
- LEFT JOIN条件写在where里是不会多查出数据来的
因为WHERE条件是对前面整个数据集进行查询,但如果条件放在ON里是会把在前表不在后表的数据查出来的
- 第八届蓝桥杯JavaB---承压计算
标题:承压计算 X星球的高科技实验室中整齐地堆放着某批珍贵金属原料. 每块金属原料的外形.尺寸完全一致,但重量不同. 金属材料被严格地堆放成金字塔形. 7 5 8 7 8 8 9 2 7 2 8 1 ...
- form-inline+form-group 实现表单横排显示(Bootstrap)
运行后的效果如下: 使用时要注意如下: 如果form元素有form-line修饰,那么form-group 所修饰的元素内部只能包含一个元素,否则,不会达到预期效果
- [JS] 屏蔽右键
if (window.Event) document.captureEvents(Event.MOUSEUP); function nocontextmenu() { event.cancelBubb ...
- 网络请求及各类错误代码含义总结(包含AFN错误码大全)
碰见一个很奇葩的问题, 某些手机在设置了不知什么后, 某些 APP 死活 HTTPS 请求失败, 例如以 UMeng 统计HTTP 请求失败为例, Log如下: UMLOG: (Error App ...
- 【第2次会议记录_2018.5.27】—— [ 算法原理 ]:手工特征提取的概念问题。(by_wanghao)
1.提取 特征点 .特征描述子 与 提取特征向量 之间的区别: (1).特征点:指的是一张图片上比较有代表性的‘位置’,提取特征点就是把图片中这些有代表性的位置给标出来. (2).特征描述子:当提取出 ...
- RocketMQ学习笔记(一)eclipse版的quickstart
学而时习之,不亦说乎! 自己搭建个学习用的RocketMQ总是很麻烦,需要虚拟机环境,网络,需要安装rocketmq,启动.时间久了再去看,又不知道这个虚拟机是干嘛的了. 直接在eclipse中启动, ...
- Acronis
关于这个神奇的东西也没少折腾了我,这里是它的家:http://www.acronis.com/zh-cn/ 网上也看了一些,没有头绪,总之给我的感觉就是不明觉厉.这里小结自己的学到的一些东西,算是一整 ...
- Git学习系列之Git基本操作克隆项目(图文详解)
不多说,直接上干货! 想必,能进来看我写的这篇博文的朋友,肯定是了解过. 比如SVN的操作吧,最常见的是 检出(Check out ...), 更新 (Update ...), 以及 提交(Commi ...