学习sql(提高篇)
时间:2010-08-19 来源:icybay
SELECT TOP 2 * FROM Persons |
like 和 not like:
SELECT * FROM Persons WHERE City LIKE '%g' -- %:一个或多个字符,-:一个字符, |
in:
SELECT column(s) FROM table_name WHERE column_name IN (value1,value2,...) |
between and not between:
SELECT column(s) FROM table_name WHERE column_name BETWEEN value1 AND value2 |
as:
SELECT A AS B, C AS D FROM Table |
join:
SELECT column_name(s) FROM table_name1 INNER JOIN table_name2 ON table_name1.column_name=table_name2.column_name
|
union and union all:
SELECT column_name(s) FROM table_name1 UNION SELECT column_name(s) FROM table_name2 -- union:列出不同的值,union all:列出所有的值,允许重复 |
select into:
SELECT column_name(s) INTO new_table_name [IN externaldatabase] FROM old_tablename --把选取的列插入到创建的新的数据库表格中 |
create or alter:
CREATE DATABASE database_name ALTER TABLE Persons ADD UNIQUE (P_Id) |
ALTER TABLE Persons ALTER City SET DEFAULT 'SANDNES' ALTER TABLE Persons ALTER City DROP DEFAULT CREATE INDEX index_name ON table_name (column_name) --or unique index |
Date函数
null:
SELECT LastName,FirstName,Address FROM Persons WHERE Address IS NULL SELECT ProductName,UnitPrice*(UnitsInStock+IFNULL(UnitsOnOrder,0)) FROM Products |
DBMS:数据库管理系统,RDBMS:关系数据库管理系统