你所需要的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 ...
随机推荐
- 201621123023《Java程序设计》第14周学习总结
一.本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结与数据库相关内容. 使用数据库技术改造你的系统 2.1 简述如何使用数据库技术改造你的系统.要建立什么表?截图你的表设计. 由于我的系 ...
- php留言系统(9)
1.参照之前的(mvc框架总结)将整体框架定下来之后,那么请求默认参数将变为: //默认请求首页: //P=front //C=fIndex //A=show 1.1 找到控制器fIndexC ...
- 2018 OCP 052最新题库及答案-4
4.For which requirement should you configure shared servers? A) accommodating an increasing number o ...
- IDEA不能实时更新jsp页面的问题
第一步: 第二步 第三步: 将这三个选项 改成
- SQL注入不简单?那是你没有懂它的原理~
我们真的了解SQL注入吗? 不管用什么语言编写的Web应用,它们都用一个共同点,具有交互性并且多数是数据库驱动.在网络中,数据库驱动的Web应用随处可见,由此而存在的SQL注入是影响企业运营且最具破坏 ...
- JMeter组件之BeanShell PostProcessor的使用
1. 场景一:获取请求响应中的数据,并保存 import com.alibaba.fastjson.*; // 引入包.这个包需要先放在:<安装目录>\apache-jmeter-3.2 ...
- 阿里云服务器之hexo环境搭建
上一步主要主要讲解云服务器购买和连接云服务器,以及文件的操作.本文主要讲解利用hexo搭建自己的静态博客,在服务器中建立自己的hexo博客环境,最后达到可以远程访问,以及远程git推送到github. ...
- iOS 一张图片引发的崩溃SEGV_ACCERR
出错日志一直报SEGV_ACCERR,原因原来是第三方库SDWebImage下载图片,远程图片的json文件不对导致的闪退 解决方法: 1.command + B 编译工程(最好在编译工程时,清除下缓 ...
- JDK源码分析(10) ConcurrentLinkedQueue
概述 我们要实现一个线程安全的队列有两种实现方法一种是使用阻塞算法,另一种是使用非阻塞算法.使用阻塞算法的队列可以用一个锁(入队和出队用同一把锁)或两个锁(入队和出队用不同的锁)等方式来实现,而非阻塞 ...
- [转] gitlab 的 CI/CD 配置管理
[From] http://blog.51cto.com/flyfish225/2156602 gitlab 的 CI/CD 配置管理 (二) 标签(空格分隔):运维系列 一:gitlab CI/CD ...