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...AND...  在某个区间


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  查询前N条记录


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

相关文章
|
SQL 数据库 Python
某站点存在SQL注入,直接可进行脱库(实战可参考此方法)
某站点存在SQL注入,直接可进行脱库(实战可参考此方法)
|
4月前
|
SQL 数据库
SQL error : “No query“问题参考
本文介绍了解决SQL中"No query"错误的步骤,包括错误提示、正确的SQL语句写法,以及更多相关参考信息。错误的原因是在构建更新语句时字段赋值之间缺少逗号,导致SQL解析失败。文章还提供了正确格式的SQL语句和相关错误处理的参考链接。
SQL error : “No query“问题参考
|
7月前
|
SQL Oracle 关系型数据库
SQL 快速参考
SQL 快速参考
35 1
|
7月前
|
SQL Oracle 关系型数据库
mysql和oracle 命令行执行sql文件 数据库执行sql文件 执行sql语句
mysql和oracle 命令行执行sql文件 数据库执行sql文件 执行sql语句
83 0
|
8月前
|
SQL Oracle 关系型数据库
Oracle PL/SQL基础知识及应用案例
Oracle PL/SQL基础知识及应用案例
134 0
|
SQL 存储 关系型数据库
MySQL的第一篇文章——了解数据库、简单的SQL语句
MySQL的第一篇文章——了解数据库、简单的SQL语句
|
SQL 数据库 Python
某站点存在SQL注入,直接可进行脱库(实战可参考此方法)
首先选择需要扫描的站点,最简单粗暴的方法就是浏览器直接搜索,什么?不会?自行gu狗吧。
|
SQL 关系型数据库 MySQL
[MySQL] SQL 基础知识
[MySQL] SQL 基础知识
|
SQL NoSQL 数据库
数据库SQL Server 基础知识思维导图
数据库SQL Server 基础知识思维导图
250 0
|
SQL 数据库
SQL数据库了解参考书籍学习
SQL数据库了解参考书籍学习