数据库学习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

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • (1)select top 子句用于规定要返回的记录数目 从Websites 表中选取头两条记录 select *...
    LP_ProgramLife阅读 3,003评论 0 0
  • 首先要知道我接下来要说的数据库是关系型数据库。我们直观来看,一个数据库可由多张表构成,每张表有不重复的名称(表名)...
    LP_ProgramLife阅读 1,814评论 0 0
  • 创建表 语法 create table 表名(列+类型,列+类型); create table Websites ...
    尼尔君阅读 3,122评论 0 1
  • 时隔一个半月,再次打开简书写作页面。 最近这一个半月,一直在找工作,宣讲会,面试的忙碌中度过的。 忙碌不能忘了学习...
    月出宛丘阅读 3,379评论 4 2
  • 还有十来分钟高铁就要发车,而此时我在高铁站门口等候安检,排在我前面有二十来个旅客,此时我的心情是焦虑不安的,我担心...
    皖尘阅读 3,818评论 0 0

友情链接更多精彩内容