(1)select語句
select * from website
select name from website
select name country? from website
(2)在表中一個列可能包含多個重復(fù)值,有時候希望列出不同(distinct)的值
select distinct country from websites
(3)where子句用于提取那些滿足制定標準的記錄
select * from Websites where country = ‘CN’;
select * from websites where id= 1;
SQL使用單引號來引用文本值,文本字段使用單引號,數(shù)字字段不使用
(4)如果在第一個條件第二個條件都成立,則and運算符顯示一條記錄,只有一個成立則是OR
select * from Websites where country = ‘CN’ and alexa >50;
select * from Websites where country = ‘USA’ or country = ‘CN’;
select * from Websites where alexa >15 and (country = ‘CN’ or country = ‘USA’);
(5)order by 關(guān)鍵字用于對結(jié)果集按照一個列或者多個列進行排序,默認升序,降序desc
select * from Websites order by alexa;
select* from Websites order by alexa DESC;
select *from Websites order by country, alexa;
(6)insert into用于向表中插入新記錄
假如像websites表中插入一個新行
insert into websites (name, url, alexa,country) values(‘百度’,’https://www.baidu.com/’,’4’,’CN’);
在指定列插入數(shù)據(jù)
insert into Websites (name,url, country)values (‘stackoverflow’,’http://stackoverflow.com/’,’IND’);
(7)update用于更新表中存在記錄
update Websites set alexa = ‘5000’,country = ‘USA’ where name=‘菜鳥教程’;
(8)用于刪除表中的行
delect from Websites where name= ‘百度’ and country=‘CN’;
不刪除表情況下刪除所有行
delect from Websites或 delect * from Websites