简单的SQL语句记录

SQL是关系型数据库的查询语言,因为不常用所以经常忘记。这里记录一些简单的命令,以备查询。

注意SQL语句需要以;号结尾.

  1. SQL SELECT Statement:
SELECT column1, column2....columnN 
FROM table_name;
  1. SQL DISTINCT Clause:
SELECT DISTINCT column1, column2....columnN
FROM table_name;
  1. SQL WHERE Clause:
SELECT column1, column2....columnN
FROM table_name
WHERE CONDITION;
  1. SQL AND/OR Clause:
SELECT column1, column2....columnN
FROM table_name
WHERE CONDITION-1 {AND|OR} CONDITION-2;
  1. SQL IN Clause:
SELECT column1, column2....columnN
FROM table_name
WHERE column_name IN (val-1, val-2,...val-N);
  1. SQL BETWEEN Clause:
SELECT column1, column2....columnN
FROM table_name
WHERE column_name BETWEEN val-1 AND val-2;
  1. SQL LIKE Clause:
SELECT column1, column2....columnN
FROM table_name
WHERE column_name LIKE { PATTERN };
  1. SQL ORDER BY Clause:
SELECT column1, column2....columnN
FROM table_name
WHERE CONDITIONORDER BY column_name {ASC|DESC};
  1. SQL GROUP BY Clause:
SELECT SUM(column_name)
FROM table_name
WHERE CONDITIONGROUP BY column_name;
  1. SQL COUNT Clause:
SELECT COUNT(column_name)
FROM table_name
WHERE CONDITION;
  1. SQL HAVING Clause:
SELECT SUM(column_name)
FROM table_name
WHERE CONDITIONGROUP BY column_name
HAVING (arithematic function condition);
  1. SQL CREATE TABLE Statement:
CREATE TABLE table_name(
column1 datatype,
column2 datatype,
column3 datatype,
.....
columnN datatype,
PRIMARY KEY( one or more columns )
);
  1. SQL DROP TABLE Statement:
DROP TABLE table_name;
  1. SQL CREATE INDEX Statement :
CREATE UNIQUE INDEX index_name
ON table_name ( column1, column2,...columnN);
  1. SQL DROP INDEX Statement :
ALTER TABLE table_name DROP INDEX index_name;
  1. SQL DESC Statement :
DESC table_name;
  1. SQL TRUNCATE TABLE Statement:
TRUNCATE TABLE table_name;
  1. SQL ALTER TABLE Statement:
ALTER TABLE table_name {ADD|DROP|MODIFY} column_name {data_ype};
  1. SQL ALTER TABLE Statement (Rename) :
ALTER TABLE table_name RENAME TO new_table_name;
  1. SQL INSERT INTO Statement:
INSERT INTO table_name( column1, column2....columnN)
VALUES ( value1, value2....valueN);
  1. SQL UPDATE Statement:
UPDATE table_name
SET column1 = value1, column2 = value2....columnN=valueN
[ WHERE CONDITION ];
  1. SQL DELETE Statement:
DELETE FROM table_name
WHERE {CONDITION};
  1. SQL CREATE DATABASE Statement:
CREATE DATABASE database_name;
  1. SQL DROP DATABASE Statement:
DROP DATABASE database_name;
  1. SQL USE Statement:
USE database_name;
  1. SQL COMMIT Statement:
COMMIT;
  1. SQL ROLLBACK Statement:
ROLLBACK; 

这些内容来自:http://www.tutorialspoint.com/sql/sql-syntax.htm 这是一个学习SQL的好站点。

    原文作者:ntop
    原文地址: https://www.jianshu.com/p/ee9b11f7984e
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞