W3Cschool
恭喜您成為首批注冊用戶
獲得88經(jīng)驗值獎勵
數(shù)據(jù)庫通常包含一個或多個表。每個表都用一個名稱標(biāo)識(例如,"Customers"或"Orders")。該表包含帶有數(shù)據(jù)(行)的記錄。
在本教程中,我們將使用著名的Northwind示例數(shù)據(jù)庫(包括MSAccess和MSSQLServer)。
下面是選自 "Customers" 表的數(shù)據(jù):
CustomerID | CustomerName | ContactName | Address | City | PostalCode | Country |
---|---|---|---|---|---|---|
1
|
Alfreds Futterkiste | Maria Anders | Obere Str. 57 | Berlin | 12209 | Germany |
2 | Ana Trujillo Emparedados y helados | Ana Trujillo | Avda. de la Constitución 2222 | México D.F. | 05021 | Mexico |
3 | Antonio Moreno Taquería | Antonio Moreno | Mataderos 2312 | México D.F. | 05023 | Mexico |
4
|
Around the Horn | Thomas Hardy | 120 Hanover Sq. | London | WA1 1DP | UK |
5 | Berglunds snabbk?p | Christina Berglund | Berguvsv?gen 8 | Lule? | S-958 22 | Sweden |
上面的表包含五條記錄(每一條對應(yīng)一個客戶)和七個列(CustomerID、CustomerName、ContactName、Address、City、PostalCode 和 Country)。
您需要在數(shù)據(jù)庫上執(zhí)行的大部分操作都是使用SQL語句完成的。
以下SQL語句選擇“Customers”表中的所有記錄:
在本教程中,我們將向您解釋各種不同的SQL語句。
句法:
SELECT column_name(s) FROM table_name
句法:
SELECT [*] FROM [TableName] WHERE [condition1]
句法:
SELECT [*] FROM [TableName] WHERE [condition1] [AND [OR]] [condition2]...
句法:
SELECT column_name()
FROM table_name
ORDER BY column_name() ASC or DESC
句法:
SELECT DISTINCT column1, column2....columnN
FROM table_name;
句法:
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 LIKE { PATTERN };
句法:
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);
句法:
INSERT INTO table_name (column, column1, column2, column3, ...)
VALUES (value, value1, value2, value3 ...)
句法:
UPDATE table_name
SET column=value, column1=value1,...
WHERE someColumn=someValue
句法:
DELETE FROM tableName
WHERE someColumn = someValue
句法:
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 {ADD|DROP|MODIFY} column_name {data_ype};
句法:
ALTER TABLE table_name RENAME TO new_table_name;
句法:
USE database_name;
句法:
COMMIT;
句法:
ROLLBACK;
現(xiàn)在,通過以下題目測測看您對“SQL 語法”的掌握程度吧!
SQL語法規(guī)則:點擊此處進(jìn)行測試>>
更多測試題請參考:《SQL測驗》題庫>>
Copyright©2021 w3cschool編程獅|閩ICP備15016281號-3|閩公網(wǎng)安備35020302033924號
違法和不良信息舉報電話:173-0602-2364|舉報郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號
聯(lián)系方式:
更多建議: