SQL语句复习版

2019-02-15 00:01

一、基础

1、 说明:创建数据库

CREATE DATABASE database-name 2、说明:删除数据库 drop database dbname 2、 说明:创建新表

create table tabname(col1 type1 [not null] [primary key],col2 type2 [not null],..) 3、 根据已有的表创建新表:

A:create table tab_new like tab_old (使用旧表创建新表)

B:create table tab_new as select col1,col2… from tab_old definition only 4、 说明:删除新表

drop table tabname

5、 说明:添加主键: Alter table tabname add primary key(col)

说明:删除主键: Alter table tabname drop primary key(col)

6、 说明:创建索引:create [unique] index idxname on tabname(col….)

删除索引:drop index idxname

注:索引是不可更改的,想更改必须删除重新建。 7、 说明:增加一个列

Alter table tabname add column (col type)

8、 说明:创建视图:create view viewname as select statement

删除视图:drop view viewname 9、 说明:几个简单的基本的sql语句

选择:select * from table1 where 范围

插入:insert into table1(field1,field2) values(value1,value2) 删除:delete from table1 where 范围

更新:update table1 set field1=value1 where 范围

查找:select * from table1 where field1 like ’%value1%’ ---like的语法很精妙,查资料! 排序:select * from table1 order by field1,field2 [desc] 总数:select count as totalcount from table1

求和:select sum(field1) as sumvalue from table1 平均:select avg(field1) as avgvalue from table1 最大:select max(field1) as maxvalue from table1 最小:select min(field1) as minvalue from table1

二、提升

1、 分组:Group by:

一张表,一旦分组 完成后,查询后只能得到组相关的信息。 组相关的信息:(统计信息) count,sum,max,min,avg 分组的标准 2、 说明:复制表(只复制结构,源表名:a 新表名:b) (Access可用)

法一:select * into b from a where 1<>1(仅用于SQlServer) 法二:select top 0 * into b from a

3、 说明:拷贝表(拷贝数据,源表名:a 目标表名:b) (Access可用)

insert into b(a, b, c) select d,e,f from b;

4、 说明:前10条记录

select top 10 * form table1 where 范围 order by 字段名 5、 说明:随机取出10条数据

select top 10 * from tablename order by newid()

三、实用

1、 拷贝结构 Use 表A

Copy structure to 表B 2、 浏览报表

Report form 报表名.frx preview

3、 存储名为表名+文本框里的值的名,例如TX(X为文本框里的值) X=thisform.text1.value A=”select ….;

Into table T”+x &A

4、 SCAN循环

Scan for 条件1 where条件2 循环体 Endscan

5、 增加有效性规则

Alter table 表名 alter 字段名 set check (left(职工号,4)=”2011”) 6、 性别有效性规则 性别$”男女”

7、 储存结果存到文本文件中的方法 … to file 文件名.txt 8、 时间的暂停

Thisform.timer.interval=0 9、 让标签显示时间

画一个计时器,在计时器的timer时间中输入thisform..label1.caption=time()


SQL语句复习版.doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:人教版九年级数学下册第二十九章之29.2.1 三视图 测试题

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: