常用sql相关
1修改基本表
添加列 alter table tableName add<新列名><数据类型>[完整性约束]
删除列 alter table tableName drop<新列名><数据类型>[完整性约束]
2创建
建表create table tableName(
id primary key AUTO_INCREMENT(mysql);
id primary key identity(1,1)(sql server)
)
建立索引
create index OID_IDX on 表名(number);
create unique index oin_idx on 表名(number);创建唯一索引
3 删除
删除索引 drop index <索引名>
删除表 drop table <表名>
4 sql功能
数据查询 select
数据定义 create drop alter
数据操控 insert update delete
数据控制 grant(授权) revoke(收回权限)
(1) 数据查询
select * from tableName where <条件表达式> group by<列名>[having<条件>] order by<列名>[ASC DESC]
select distinct Sno from sc 查询数据去掉重复行
常见的查询条件
比较 = ,>,<,<=,<=,!=,<>,!<,!>,
确定范围 between and |not between and
确定集合 in ,not in
字符匹配 like ,not like like '<匹配符>' 匹配符可以包含通配符%和_
空值 is null ,is not null
多重条件(逻辑运算) and,or,not
select a.name,a.mialbox from a where EXISTS(select b.name from b where a.name=b.name)
联接查询join
select a.number,a,name,b.age,b.sort from a join b on a.number=b.number
inner join 内联接 用于返回两个表中要查询的列数据 left join right join
常见运算以及聚集函数
ABS(x)返回绝对值
&
相关文档:
之前偶然逛网页的时候看到的,详细的网址忘记copy过来了,真是抱歉。觉得简单易懂,所以转了,嘻嘻
有关分页 SQL 的资料很多,有的使用存储过程,有的使用游标。本人不喜欢使用游标,我觉得它耗资、效率低;使用存储过程是个不错的选择,因为存储过程是经过预编译的,执行效率高,也更灵活。先看看单条 SQL 语句的分页 SQL ......
Sql Server 查询sql执行各个阶段的时间
set statistics io on
set statistics time on
set statistics profile on
go
[你的sql语句]
go
set statistics io off
set statistics time off
set statistics profile off
我运行:
set statistics io on
set statistics time on
set statistics profile on ......
几道经典的SQL笔试题目(有答案)
(1)表名:购物信息
购物人 商品名称 数量
A 甲 2
B 乙 &n ......
http://www.cnblogs.com/Mainz/archive/2008/12/20/1358897.html
什么情况下使用表变量?什么情况下使用临时表?
表变量:
DECLARE @tb table(id int identity(1,1), name varchar(100))
INSERT @tb
SELECT id, name
from mytable
WHERE name like ‘zhang%&rsquo ......
在数据库开发过程中,当你检索的数据只是一条记录时,你所编写的事务语句代码往往使用SELECT INSERT 语句。但是我们常常会遇到这样情况,即从某一结果集中逐一地读取一条记录。那么如何解决这种问题呢?游标为我们提供了一种极为优秀的解决方案。 1.1 游标和游标的优点 在数据库中,游标是一个十分重要的概念。游标提供了一 ......