码迷,mamicode.com
首页 > 数据库 > 详细

SQL基础

时间:2016-11-06 02:03:50      阅读:326      评论:0      收藏:0      [点我收藏+]

标签:不同的   表名   基础   运算   rom   使用   插入数据   into   获取   

SQL 对大小写不敏感!

数据操作语言 (DML):

select - 从数据库表中获取数据

update - 更新数据库表中的数据

delete - 从数据库表中删除数据

insert into - 向数据库表中插入数据

数据定义语言 (DDL):

create database - 创建新数据库

alter database - 修改数据库

create table - 创建新表

alter table - 变更(改变)数据库表

drop table - 删除表

create index - 创建索引(搜索键)

deop index - 删除索引

 查

select 列名称,列名称 from 表名称

提示:星号(*)是选取所有列的快捷方式。

distinct 返回唯一不同的值:select distinct  列名称 from 表名称

where(有条件地从表中选取数据):select  列名称 from 表名称 where 列 运算符 值(用单引号来环绕文本值,数值不使用引号)

操作符 = <>(!=) > < >= <= between link
描述 等于 不等于 大于 小于 大于等于 小于等于 在某个范围内 搜索某种模式

 

                                    

and 和 or

select  列名称 from 表名称 where 列 运算符 值 and 列 运算符 值

select  列名称 from 表名称 where 列 运算符 值 or 列 运算符 值

select  列名称 from 表名称 where 列 (运算符 值 and 列 运算符 值) or 列 运算符 值

 order by排序(升序) desc 降序

select  列名称 from 表名称 order by 列名称(按这排序)

select  列名称 from 表名称 order by 列名称(第一排序),列名称(第二排序)

select  列名称 from 表名称 order by 列名称(第一排序)desc(降序),列名称(第二排序)asc(升序)

insert into 表名称 values (值1,值2...)    //插入行数据

insert into 表名称(列名称,列名称...) values (值1,值2...)    //插入列数据

update 表名称 set 列名称 = 新值 where 列名称 = 某值

update 表名称 set 列名称 = 新值,列名称 = 新值 where 列名称 = 某值

delete from 表名称 where 列名称 = 值

delete from 表名称/delete * from 表名称   //在不删除表的情况下删除所有的行

 

top:规定要返回的记录的数目

select top 数字 列名称 from  表名称

select top 50 percent 列名称 from  表名称  //取50%的数据,单数则多取一条

link:在 WHERE 子句中搜索列中的指定模式   not

select * from 表名称 where 列名称 link ‘字母%‘   //以字母开始

提示:"%" 可用于定义通配符(模式中缺少的字母)

select * from 表名称 where 列名称 link ‘%字母‘   //以字母结尾

select * from 表名称 where 列名称 link ‘%字母%‘   //包含字母(可多个)

select * from 表名称 where 列名称 not link ‘%字母%‘   //不包含字母(可多个)

通配符 描述
% 替代一个或多个字符
_ 仅替代一个字符
[charlist] 字符列中的任何单一字符
[^charlist]  或者 [!charlist] 不在字符列中的任何单一字符

 

 

 

 

 

select * from 表名称 where 列名称 link ‘字母_字母_字母‘

select * from 表名称 where 列名称 link ‘[字母1字母2字母3]%‘   //从表中选取列以 "字母1" 或 "字母2" 或 "字母3" 开头的

in:允许我们在 WHERE 子句中规定多个值

select * from 表名称 where 列名称 in (值1,值2...)

between... and:选取介于两个值之间的数据范围 not

select * from 表名称 where 列名称 between 值1 and 值2  //介于 "值1"(包括)和 "值2"(不包括)之间

select * from 表名称 where 列名称 not between 值1 and 值2  

SQL基础

标签:不同的   表名   基础   运算   rom   使用   插入数据   into   获取   

原文地址:http://www.cnblogs.com/sctnl/p/6034391.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!