数据库学习01

(1)select语句

select * from website

select name from website

select name country  from website

(2)在表中一个列可能包含多个重复值,有时候希望列出不同(distinct)的值

select distinct country from websites

(3)where子句用于提取那些满足制定标准的记录

select * from Websites where country = ‘CN’;

select * from websites where id= 1;

SQL使用单引号来引用文本值,文本字段使用单引号,数字字段不使用

(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 关键字用于对结果集按照一个列或者多个列进行排序,默认升序,降序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’);

在指定列插入数据

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

你可能感兴趣的:(数据库学习01)