你所需要的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 ...
随机推荐
- Keepalived_vrrp: ip address associated with VRID not present in received packet
keepalived常见的启动报错: 5913 May 16 15:26:04 localhost Keepalived_vrrp: ip address associated with VRID n ...
- [Objective-C语言教程]类型转换(20)
类型转换是一种将变量从一种数据类型转换为另一种数据类型的方法. 例如,如果要将long值存储到简单整数(int)中,则可以将long类型转换设置为int.使用强制转换运算符将值从一种类型转换为另一种类 ...
- 【JVM】jvm启动参数
-server -Xmx2048m -Xms1500m -Xmn1024m -XX:PermSize=128m -Xss256k -XX:+DisableExplicitGC -XX:+UseConc ...
- C++基础知识:成员函数、对象拷贝、私有成员
一.综述 类是我们自己定义的数据类型(新类型) 设计类时要考虑的角度: (1)站在设计和实现者的角度来考虑 (2)站在使用者的角度来考虑 (3)父类,子类 二.类基础 (1)一个类就是一个用户自己定义 ...
- javascript举例介绍事件委托的典型使用场景
在了解什么是DOM事件以及给DOM事件绑定监听器的几种方法后,我们来谈谈事件委托. 1. e.target 和 e.currentTarget 当我们给目标元素target 绑定一个事件监听器targ ...
- Java NIO学习与记录(一):初识NIO
初识 工作中有些地方用到了netty,netty是一个NIO框架,对于NIO却不是那么熟悉,这个系列的文章是我在学习NIO时的一个记录,也期待自己可以更好的掌握NIO. 一.NIO是什么? 非阻塞式I ...
- #PHP# 华为云 API 方式发送短信
使用给华为云 消息 服务 API 方式发送短信 代码来自华为云,已通过测试 <?php /** * 华为云发送短信示例代码 * 本段代码需要使用自己的配置信息才能正常运行,出配置信息外,不需要改 ...
- FindLine把多行查找改为多行替换
Sub FindLine() Dim textSelection As TextSelection textSelection = DTE.ActiveDocument.Selection textS ...
- C# string 特殊的引用类型
.Net 框架程序设计(修订版)中有这样一段描述:String类型直接继承自Object,这使得它成为一个引用类型,也就是说线程上的堆栈上不会驻留有任何字符串.(译注:注意这里的“直接继承”.直接继承 ...
- 安装TD出现Unknown user name or bad password问题
在Server 2003 sp2上安装TD8.0 出现Unknown user name or bad password,是因为2003启用了DEP保护. 关闭系统的DEP保护就可以了. 方法如下 ...