你所需要的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 ...
随机推荐
- 【OCP认证12c题库】CUUG 071题库考试原题及答案(28)
28.choose the best answer Evaluate the following SQL statement: SQL> SELECT promo_id, promo_categ ...
- Getting Started with Elastic Search in .NET
I have been working on many application during my career. Many if not all had some searching capabi ...
- C++与C的区别二
1. new,delete的局部重载: #include <iostream> using namespace std; ; class myclass { public: myclass ...
- springMVC请求注解@RequestMapping各个属性值
最近遇到了一个采用fastJson传输数据的方式,搞了半天,总是感觉模糊,觉得自己有必要在这里做一个系统的总结,今天先从@RequestMapping的属性开始,采用REST 风格的 URL 请求,R ...
- ArrayList 和 Vector 的区别
这两个类都实现了 List 接口( List 接口继承了 Collection 接口),他们都是有序集合,即存储在这两个集合中的元素的位置都是有顺序的,相当于一种动态的数组,我们以后可以按位置索引号取 ...
- pickle 模块学习 常用方法
内容提要: 1: pickle的主要作用 pickle主要用于python 于python 之间进行文件传出,网络传输 他同json 一样也是有4个函数 pickle.dumps(iterable) ...
- 实现函数 ToLowerCase()
/** * 实现函数 ToLowerCase(),该函数接收一个字符串参数 str, 并将该字符串中的大写字母转换成小写字母,之后返回新的字符串. * 输入: "Hello" * ...
- Thread.Sleep(1000) 、Task.Delay(1000).Wait() 区别
public static Task Delay(int millisecondsDelay, CancellationToken cancellationToken){ if (millise ...
- Focal Loss 的前向与后向公式推导
把Focal Loss的前向和后向进行数学化描述.本文的公式可能数学公式比较多.本文尽量采用分解的方式一步一步的推倒.达到能易懂的目的. Focal Loss 前向计算 其中 是输入的数据 是输入的标 ...
- 响应式Web设计-一种优雅的掌上展现
入门 flat - style (too many ad.) writeshell