1 / 36
文档名称:

sql数据库学习笔记.doc

格式:doc   大小:227KB   页数:36页
下载后只包含 1 个 DOC 格式的文档,没有任何的图纸或源代码,查看文件列表

如果您已付费下载过本站文档,您可以点这里二次下载

分享

预览

sql数据库学习笔记.doc

上传人:文库旗舰店 2018/5/29 文件大小:227 KB

下载得到文件列表

sql数据库学习笔记.doc

文档介绍

文档介绍:sql(数据库学****笔记)
授课教师:彭开东
目录
Sql(基础) 1
sql(数据库完整性) 2
sql(索引) 3
sql(软件项目流程) 3
查询(单表查询) 4
数据统计 5
SQL(多表查询与统计) 7
SQL(视图) 9
sql语法 10
sql(事务处理、游标) 17
21
25
、游标、触发器 27
函数 32
,数据导入与导出 35
35
Sql(基础)
数据库包括:系统数据库用户数据库
系统数据库:(sql安装后自带的数据库)sql自身系统维护,并作为数据库字典(master msdb….)northwind pubs sql帮助系统
用户数据库:用户自定义添加的数据库
逻辑名:(master madb….)物理名:其sql安装路径下的数据库名(…..)
新建数据库
1、在默认路径建库
企业管理器(人工操作过程)
通过查询分析器建库(通过代码)
create database 库名添加数据库
drop database 库名丢掉数据库
2、指定路径建库
修改数据库路径
3、在指定路径下建立多文件系统数据库
**.mdf 主数据库文件**.ndf 次数据库文件**.ldf 日志文件
四、新建数据表
概念:数据库卡最基本的对象,其它与其为基础
建结构
放入记录
代码:create database business
on
(name=business_data,
filename='j:\business_mdf',
size=10,
maxsize=50,
filegrowth=5)
log on
(name=business_log,
filename='j:\business_log',
size=10,
maxsize=20,
filegrowth=5)
go
sql(数据库完整性)
一、数据库的完整性
空值
默认值
约束
默认
规则
主键与外键
索引
自定义数据类型
计算字段域
默认值:字符、数字、日期、”_____”
约束:1、字符 in(————)
2、数字……and……
3、日期 between conseraint check
代码:
create table teacher
(atch varchar(8) not null,xm varchar(8) not null,km varchar(8) not null primary key(atch))
create table steute
(atch varchar(8) not null, name varchar(8) not null,kk varchar(8) not null,foreign KEY(atch) references teacher(atch) )
create table sheep(km varchar(8) not null,dj varchar(8) not null,sl varchar(6)not null,zs as (dj*sl))
sql(索引)
索引
作用:提高查询速度(优化数据库)
1、单字段索引
族索引(进行排序) 唯一索引(不重复) 非唯一索引(重复)
非族索引(不进行排序)
多字段索引
例如:create index index1 on table(字段)
drop index table index1
create unique index index1 on table
create clustered
计算字段域
create putertable(…,…,…,…,as…*…)
三、自定义数据类型
代码:
--drop index
--create index index1 on users(sjh)
--drop index
--create unique index index1 on users(sjh)
--drop index
--create unique clustered index index1 on users(sjh)
--drop index
create unique clustered index ind