SQL 语句快速参考

来自 W3CSchool 的 SQL 快速参考


SQL 语句 语法
AND / OR SELECT column_name(s)
FROM table_name
WHERE condition
AND|OR condition
ALTER TABLE ALTER TABLE table_name 
ADD column_name datatype

or

ALTER TABLE table_name 
DROP COLUMN column_name

AS (alias) SELECT column_name AS column_alias
FROM table_name

or

SELECT column_name
FROM table_name AS table_alias

BETWEEN SELECT column_name(s)
FROM table_name
WHERE column_name
BETWEEN value1 AND value2
CREATE DATABASE CREATE DATABASE database_name
CREATE TABLE CREATE TABLE table_name
(
column_name1 data_type,
column_name2 data_type,
column_name2 data_type,
...
)
CREATE INDEX CREATE INDEX index_name
ON table_name (column_name)

or

CREATE UNIQUE INDEX index_name
ON table_name (column_name)

CREATE VIEW CREATE VIEW view_name AS
SELECT column_name(s)
FROM table_name
WHERE condition
DELETE DELETE FROM table_name
WHERE some_column=some_value

or

DELETE FROM table_name 
(Note: Deletes the entire table!!)

DELETE * FROM table_name 
(Note: Deletes the entire table!!)

DROP DATABASE DROP DATABASE database_name
DROP INDEX DROP INDEX table_name.index_name (SQL Server)
DROP INDEX index_name ON table_name (MS Access)
DROP INDEX index_name (DB2/Oracle)
ALTER TABLE table_name
DROP INDEX index_name (MySQL)
DROP TABLE DROP TABLE table_name
GROUP BY SELECT column_name, aggregate_function(column_name)
FROM table_name
WHERE column_name operator value
GROUP BY column_name
HAVING SELECT column_name, aggregate_function(column_name)
FROM table_name
WHERE column_name operator value
GROUP BY column_name
HAVING aggregate_function(column_name) operator value
IN SELECT column_name(s)
FROM table_name
WHERE column_name
IN (value1,value2,..)
INSERT INTO INSERT INTO table_name
VALUES (value1, value2, value3,....)

or

INSERT INTO table_name
(column1, column2, column3,...)
VALUES (value1, value2, value3,....)

INNER JOIN SELECT column_name(s)
FROM table_name1
INNER JOIN table_name2 
ON table_name1.column_name=table_name2.column_name
LEFT JOIN SELECT column_name(s)
FROM table_name1
LEFT JOIN table_name2 
ON table_name1.column_name=table_name2.column_name
RIGHT JOIN SELECT column_name(s)
FROM table_name1
RIGHT JOIN table_name2 
ON table_name1.column_name=table_name2.column_name
FULL JOIN SELECT column_name(s)
FROM table_name1
FULL JOIN table_name2 
ON table_name1.column_name=table_name2.column_name
LIKE SELECT column_name(s)
FROM table_name
WHERE column_nameLIKE pattern
ORDER BY SELECT column_name(s)
FROM table_name
ORDER BY column_name [ASC|DESC]
SELECT SELECT column_name(s)
FROM table_name
SELECT * SELECT *
FROM table_name
SELECT DISTINCT SELECT DISTINCT column_name(s)
FROM table_name
SELECT INTO SELECT *
INTO new_table_name [IN externaldatabase]
FROM old_table_name

or

SELECT column_name(s)
INTO new_table_name [IN externaldatabase]
FROM old_table_name

SELECT TOP SELECT TOP number|percent column_name(s)
FROM table_name
TRUNCATE TABLE TRUNCATE TABLE table_name
UNION SELECT column_name(s) FROM table_name1
UNION
SELECT column_name(s) FROM table_name2
UNION ALL SELECT column_name(s) FROM table_name1
UNION ALL
SELECT column_name(s) FROM table_name2
UPDATE UPDATE table_name
SET column1=value, column2=value,...
WHERE some_column=some_value
WHERE SELECT column_name(s)
FROM table_name
WHERE column_name operator value

来源://www.w3cschool.cn/sql/sql-quickref.html

 

时间: 2024-10-07 17:34:08

SQL 语句快速参考的相关文章

使用Sql语句快速将数据表转换成实体类

开发过程中经常需要根据数据表编写对应的实体类,下面是使用sql语句快速将数据表转换成对应实体类的代码,使用时只需要将第一行'TableName'引号里面的字母换成具体的表名称就行了: declare @TableName sysname = 'TableName' declare @Result varchar(max) = 'public class ' + @TableName + ' {' select @Result = @Result + ' public ' + ColumnType

如何通过sql语句快速生成 删除表的sql

select 'drop table '+name tablename from sysobjects where xtype='U' and name like 'ta_bsk%' 备注: 从系统表(sysobjects)中查询类型是用户表(xtype='U')表名以ta_bsk开头的表名(name like '%ta_bsk%'),拼接上'drop table'就生成了我想要的sql语句了.哈哈

MSSql使用SQL语句快速查看表对的就说明,及表字段描述及字段类型

--表描述 SELECT tbs.name 表名,ds.value 描述 FROM sys.extended_properties ds LEFT JOIN sysobjects tbs ON ds.major_id=tbs.id WHERE ds.minor_id=0 and tbs.name='Warrant_BaseInfo';--表名 --快速查看表结构 SELECT CASE WHEN col.colorder = 1 THEN obj.name ELSE '' END AS 表名,

SQL语句快速查询存在某个值的所有存储过程

不多说,直接上代码 SELECT obj.Name 存储过程名, sc.TEXT 存储过程内容 FROM syscomments sc INNER JOIN sysobjects obj ON sc.Id = obj.ID WHERE sc.TEXT LIKE '%' + 'AdID' + '%' AND TYPE = 'P' 其中在AdID中就是你要搜索的值

Sql Server 查看当前正在执行的Sql 语句

查看Sql Server 当前正在执行的Sql 语句,可以使用 sys.sysprocesses 或 sys.dm_exec_requests,由于sys.sysprocesses是为了向后兼容而保留的,所以,推荐使用DMV:sys.dm_exec_requests 一,使用sys.sysprocesses Contains information about processes that are running on an instance of SQL Server. These proce

Sql Server中如何快速修正SQL 语句错误

本文将和大家讨论一些关于找SQL 错误的问题. 现在的系统基本都是需要用到数据库的,既然用到数据库我们就要写SQL 脚本,常用的做法是现在Microsoft Sql Server Management Sudio写好调试好,然后贴到 代码中,但这样就能保证我们的SQL 脚本正常运行吗?那如果带参数的SQL 或存储过程出现问题呢?如果数据出现问题,我们应该怎么找出错误的SQL 呢? 带着这个疑问,开始我们今天的讨论.以前用代码和数据库打交道,出现数据问题,我们会打个断点一步一步的调试,就像这样:

SQL 快速参考

SQL 快速参考 SQL 语句 语法 AND / OR SELECT column_name(s)FROM table_nameWHERE conditionAND|OR condition ALTER TABLE ALTER TABLE table_name ADD column_name datatype or ALTER TABLE table_name DROP COLUMN column_name AS (alias) SELECT column_name AS column_alia

SQL Server快速生成SQL增删改查语句

你还在手敲代码生成SQL语句吗?你还在为因为马虎出错的SQL语句而感到无语吗?你还在为不知怎样表达复杂的SQL语句而纠结吗?如果你的回答为"是",那你就OUT啦,快来试试应用SQL Server资源管理器快速生成SQL语句吧. 首先,打开SQL Server2008,在菜单栏"查询"下拉菜单中找到"在编辑器中设计查询",如下图: 在打开的查询设计器窗口中添加要进行操作的数据库表. 在添加的表内下方空白部分右键单击鼠标,在弹出菜单中单击"

C#.NET 大型企业信息化系统集成快速开发平台 4.1 版本 - 面向数据库SQL语句的应用开发一

我的梦想是给大家提供一个工具.可以用他来提高工作效率.就像战争上,你有一个得心应手的武器一个道理.  给大家一个性能良好的信息化武器,就是我的梦想. 有一个朋友来信息如下: 我就是企业维护信息的,也不大编程,懂点吧,但是也忘得差不多.最近看了点书,微软的,java的,我感觉自己数据库语句还行,持久层也就是固定套路,但是控制和表现没有些积累就不大好弄了,比较见功力,特别是表现层,技术也杂.粗略认识吧,我就想做点信息系统,台账之类,你的程序能帮到我吗,有详细说明吗? 我们有充分的例子程序,模板程序,