W3Cschool
恭喜您成為首批注冊用戶
獲得88經(jīng)驗值獎勵
SQL 遵循一組稱為“語法”的規(guī)則和指南。本教程列出了所有的 SQL 基礎(chǔ)語法供你快速學(xué)習(xí) SQL 之用。
所有的 SQL 語句都以下列關(guān)鍵字之一開始:SELECT、INSERT、UPDATE、DELETE、ALTER、DROP、CREATE、USE、SHOW,并以一個分號(;)結(jié)束。
有一點需要特別注意:SQL 不區(qū)分大小寫,也就是說 SELECT 和 select 在 SQL 語句中有相同的含義。然而,MySQL 在表的名稱方面并不遵循此規(guī)定。所以,如果你在使用 MySQL 的話,你需要在程序中嚴(yán)格按照它們在數(shù)據(jù)庫中名字進(jìn)行使用。
本教程列出的所有的例子都在 MySQL 下進(jìn)行了測試。
SELECT column1, column2....columnN
FROM table_name;
SELECT DISTINCT column1, column2....columnN
FROM table_name;
SELECT column1, column2....columnN
FROM table_name
WHERE CONDITION;
SELECT column1, column2....columnN
FROM table_name
WHERE CONDITION-1 {AND|OR} CONDITION-2;
SELECT column1, column2....columnN
FROM table_name
WHERE column_name IN (val-1, val-2,...val-N);
SELECT column1, column2....columnN
FROM table_name
WHERE column_name BETWEEN val-1 AND val-2;
SELECT column1, column2....columnN
FROM table_name
WHERE column_name LIKE { PATTERN };
SELECT column1, column2....columnN
FROM table_name
WHERE CONDITION
ORDER BY column_name {ASC|DESC};
SELECT SUM(column_name)
FROM table_name
WHERE CONDITION
GROUP BY column_name;
SELECT COUNT(column_name)
FROM table_name
WHERE CONDITION;
SELECT SUM(column_name)
FROM table_name
WHERE CONDITION
GROUP BY column_name
HAVING (arithematic function condition);
CREATE TABLE table_name(
column1 datatype,
column2 datatype,
column3 datatype,
.....
columnN datatype,
PRIMARY KEY( one or more columns )
);
DROP TABLE table_name;
CREATE UNIQUE INDEX index_name
ON table_name ( column1, column2,...columnN);
ALTER TABLE table_name
DROP INDEX index_name;
DESC table_name;
TRUNCATE TABLE table_name;
ALTER TABLE table_name RENAME TO new_table_name;
INSERT INTO table_name( column1, column2....columnN)
VALUES ( value1, value2....valueN);
UPDATE table_name
SET column1 = value1, column2 = value2....columnN=valueN
[ WHERE CONDITION ];
DELETE FROM table_name
WHERE {CONDITION};
CREATE DATABASE database_name;
DROP DATABASE database_name;
USE database_name;
COMMIT;
ROLLBACK;
Copyright©2021 w3cschool編程獅|閩ICP備15016281號-3|閩公網(wǎng)安備35020302033924號
違法和不良信息舉報電話:173-0602-2364|舉報郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號
聯(lián)系方式:
更多建議: