# sql
命令 | 說明 |
---|---|
select | 從數據庫中提取數據 |
update | 更新數據庫中的數據 |
delete | 從數據庫中刪除數據 |
insert into | 向數據庫中插入數據 |
create database | 建立新的數據庫 |
alter database | 修改數據庫 |
create table | 建立新表 |
alter table | 改變數據庫表 |
drop table | 刪除表 |
create index | 建立索引 |
drop index | 刪除索引 |
注意,SQL語句不區分大小寫數據庫
select column_name, column_name from table_name; select * from table_name;
seletc distinct column_name, column_name from table_name;
select column_name, colunm_name from table_name where column_name operator value;
select * from Customers where country='Mexico';
運算符 | 描述 |
---|---|
= | 等於 |
<> | 不等於,有時寫成 != |
> | 大於 |
< | 小於 |
>= | 大於等於 |
<= | 小於等於 |
between | 在某個範圍內 |
like | 搜索某種模式 |
in | 指定針對某個列的多個可能值 |
select * from Customers where country='china' and city='beijing'; SELECT * FROM Customers WHERE Country='Germany' AND (City='Berlin' OR City='München');
select column_name, column_name from table_name order by column_name, column_name asc|desc;
select column_name from customers order by country;
select column_name from customers order by country desc;
insert into table_name values (value1, value2, value3,...)
insert into table_name (column1, column2, column3,...) values (value1, value2, value3,...)
update table_name set column1=value1, column2=value2,... where some_column=som_value;
delete from table_name where some_column=some_value;
delte from table_name; or delete * from table_name;