你所需要的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 ...
随机推荐
- django系列3.2--url的别名和反向解析 reverse
命名URL和反向解析 在网页中某些要提交的地址等,需要改变的时候,此时网页过多,如果一个一个的去改,工作量巨大,这时就可以用到命名url,在html文件的模版中,只写命名,这样当需要我们改变urls. ...
- 解决:sql server无法在C盘下创建database/操作系统错误5(拒绝访问)
问题: ——无法在C盘的任何位置创建数据库文件 ——在非系统盘的F盘可以创建数据库文件 解决方法1:禁用“以管理员批准模式运行所有管理员" 解决方法2:打开C盘对Users用户的完全控制权限 ...
- 深入了解java虚拟机(JVM) 第十章 字节码指令
一.字节码指令的含义 Java字节码指令由一个字节长度的,代表某种特定操作含义的数字(操作码)以及其后的零至多个代表此操作所需参数(操作数).此外字节码指令是面向操作数栈的,这里操作数栈在功能上对应实 ...
- LOJ#6046. 「雅礼集训 2017 Day8」爷(分块)
题面 传送门 题解 转化为\(dfs\)序之后就变成一个区间加,区间查询\(k\)小值的问题了,这显然只能分块了 然而我们分块之后需要在块内排序,然后二分\(k\)小值并在块内二分小于它的元素--一个 ...
- CTF中密码学一些基础
本文作者:i春秋签约作家MAX. 凯撒密码作为一种最为古老的对称加密体制,在古罗马的时候都已经很流行,他的基本思想是:通过把字母移动一定的位数来实现加密和解密. 给大家先找两道题,来一起探讨基础密码学 ...
- nginx配置文件中,location字段里面的root字段和别名alias
1. location里面的root例子 server{ listen ; server_name www.wzw.com; location /www { root /data/; //设置虚拟主机 ...
- navicat for oracle 创建表ID字段的自动递增
Oracle数据库创建表ID字段的自动递增 将表t_uaer的字段ID设置为自增:(用序列sequence的方法来实现) ----创建表 Create table t_user( Id numbe ...
- 【算法笔记】A1054 The Dominant Color
1054 The Dominant Color (20 分) Behind the scenes in the computer's memory, color is always talked ...
- basic algorithm- 20190416-20190425
binary search 14.https://www.lintcode.com/problem/first-position-of-target/description 74.https://ww ...
- (热死你)Resin https ssl Linux 配置,实战可用
(热死你)Resin https ssl Linux 配置,实战可用 一.配置resin 1.在resin服务器中创建目录keys文件和openssl.conf,格式内容如下: #先复制以下的内容: ...