1.select 用于查询数据
示例:
select * from websites; 查询创建的websites表数据。 注意后面的分号,分号表示一段SQL命令的结束。
select * from websites where name='淘宝'; 查询websites表中的‘淘宝’的数据, 号表示查询这个websites表的所有数据。这里号可以写成表的某一列。
select name from websites; 或 select name from websites where country='CN';
2.select disinct 用于返回唯一不同的值。
示例:
select distinct country from websites; 查询websites表中country唯一不同的值。
3.where 子句用于提取那些指定标准的数据
运算符
、=、 50;
SELECT * FROM Websites WHERE country='CN' or alexa > 50;
结合运用
select * from websites where alexa >15 and ( country='CN' or country='US' );
5.order by 对于查询的数值进行排序,order by 升序, 加上desc为降序
示例:
select * from websites order by alexa; 以alexa列的数值进行升序排序
select * from websites order by country,alexa desc; 以country和Alexa的数值进行降序排序(其中由于country在前,所以country优先级高于Alexa)
6.insert into 向表中插入新数据。
示例:
insert into websites (name,url,alexa,country) values ('百度','https://www.baidu.com/','4','CN')
7.update 用于更新表中已存在的记录
示例:
update websites set alexa ='5000' , country ='USA' where name ='菜鸟教程';
注意如果不加where则会将websites整张表的数据都改了。所以在实际生产环境中管理员都会对update使用进行限制,如果使用update时没有加上where则会报错