云题海 - 专业文章范例文档资料分享平台

当前位置:首页 > sql知识点总结(完整)

sql知识点总结(完整)

  • 62 次阅读
  • 3 次下载
  • 2026/4/23 19:22:08

Sql 总结

1. 数据模型主要有:层次模型,网状模型,关系模型, 2. 数据库设计的步骤:需求分析,概念结构设计,逻辑结构设计,数据库物理设计,数据库实施,数据库运行和维护六个阶段。

3. 实体之间的关系:一对一、一对多、多对多。

4. 数据库文件主要有:主数据文件、次数据文件、日志文件其中 次数据文件是可选的。 --这是建库的过程

if exists (select * from sysdatabases where name='tt') drop database tt create database tt on( name=tt,

filename='d:\\data\\tt.mdf', size=4mb, maxsize=50mb, filegrowth=15% ) log on( name=tt1,

filename='d:\\data\\tt1.ldf', size=5mb, maxsize=79mb, filegrowth=15% )

--这是对数据库的修改 alter database tt modify file( name=tt1, maxsize=89mb )

--增加日志文件

alter database tt add log file(

1

name=oo,

filename='d:\\data\\oo.ldf', size=5mb, maxsize=79mb, filegrowth=15% )

----查看数据库 sp_helpdb tt

5. 重要的数据类型

Int float char(size) datetime varchar(size) 6.在数据库中添加表

use tt go

if exists (select * from sysobjects where name='t_li') drop table t_li

create table t_li (

a char(4) not null, b int not null, c datetime )

insert into t_li values ('yy',78,2012-5-12) insert into t_li (a,b) values ('ttf',89) select * from t_li

--新建一个表,往表里添加t_li的数据 create table t_ti1( a char(4) not null, b int not null )

insert into t_ti1 select a,b from t_li

---这种方法不用重建 select a,b into t_li2 from t_li

select * from t_li2

2

6. 使用union关键字插入多行数据

---利用union一次插入多行数据 insert into t_li (a,b,c) select 'aa',55,2012-8-12 union select 'cc',54,2032-5-12

7. 对数据表进行操作 ---对表的修改

alter table t_li alter column a char(8) select * from t_li --添加字段

alter table t_li add d char(9) --删除字段

alter table t_li

drop column d

--表的查询

select * from t_li

8. 对字段添加约束

---添加主键约束 应该注意是主键约束字段的值不能是重复的alter table t_li

add constraint pk_a primary key(a)

---添加外键约束 alter table t_li

add constraint fr_b foreign key(b) references t_li4(b)

--添加唯一约束

alter table t_li

add constraint t_li_uq unique(a)

---添加默认约束 alter table t_li

add constraint t_li_df default(20) for b

--添加check约束 alter table t_li

add constraint t_li_ck check(b between 0 and 50) ---删除约束

3

alter table t_li

drop constraint t_li_ck

9. 对于表的查询(单表查询)

select *from Customers

select c_ID,c_Name,c_TrueName,c_Password from Customers

-----()查询WebShop数据库中会员信息表Customers中会员的编号(c_ID)、

-----用户名(c_Name)、真实姓名(c_TrueName)、年龄(c_Age)和密码(c_Password)。 select c_ID,c_Name, c_Truename,year(getdate())-year(c_Birth) 'c_Age',c_Password from Customers

select 会员的编号=c_ID,用户名=c_Name,c_TrueName as '真实名字',c_Password '名字' from Customers

select * from Customers where c_Type='VIP'

--6)将VIP客户的编号(c_id)、姓名(c_name)、出生日期(c_birth)、籍贯(c_address)、----

----联系电话(c_phone)和地址(c_email)显示出来并以汉字标题显示列名。 select 编号=c_id, 姓名=c_name, c_birth as '出生年月', c_address 籍贯, c_phone as '联系电话', c_email '地址' from Customers where c_Type='VIP'

----()将湖南的VIP客户记录显示出来。

select * from Customers where c_Address='湖南株洲市' AND C_Type='VIP'

-----()将的客户记录显示出来。 select * from Customers where c_Email like '3.com'

----()将前%的客户记录显示出来。

select top 10 percent * from Customers ----()将姓刘的客户记录显示出来。 select * from Customers where c_TrueName like '刘%'

-----()将客户按年龄进行降序(由大到小)排序。

select year(getdate())-year(c_Birth) as 'c_Age' from Customers order by year(getdate())-year(c_Birth) desc

----()将客户按类型升序排序,如果类型相同按年龄的降序进行排序。

4

搜索更多关于: sql知识点总结(完整) 的文档
  • 收藏
  • 违规举报
  • 版权认领
下载文档10.00 元 加入VIP免费下载
推荐下载
本文作者:...

共分享92篇相关文档

文档简介:

Sql 总结 1. 数据模型主要有:层次模型,网状模型,关系模型, 2. 数据库设计的步骤:需求分析,概念结构设计,逻辑结构设计,数据库物理设计,数据库实施,数据库运行和维护六个阶段。 3. 实体之间的关系:一对一、一对多、多对多。 4. 数据库文件主要有:主数据文件、次数据文件、日志文件其中 次数据文件是可选的。 --这是建库的过程 if exists (select * from sysdatabases where name='tt') drop database tt create database tt on( name=tt, filename='d:\\data\\tt.mdf', size=4mb, maxsize=50mb, filegrowth=15% ) log on( nam

× 游客快捷下载通道(下载后可以自由复制和排版)
单篇付费下载
限时特价:10 元/份 原价:20元
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:fanwen365 QQ:370150219
Copyright © 云题海 All Rights Reserved. 苏ICP备16052595号-3 网站地图 客服QQ:370150219 邮箱:370150219@qq.com