mysq数据库管理工具navicat基本使用方法
navicat是mysql数据库的客户端查询管理工具,本文详细的介绍了该软件的基本使用方法
本文转自 http://hejiawangjava.iteye.com/blog/2245758
sql是操作数据库中数据的语句,在不同的数据库中会略有不同,如mysql,postgreSQL,oracle,sqlserver,sqlite等等,但是sql的基础select、insert、update、delete语句都是相同的,本文只是介绍如何在mysql中,利用navicat可视化工具学习sql语句的select、insert、update、delete基础,这四种语句是sql基础中的基础了,但是万变不离其中,其他复杂的语句也都是这四种语句的组合。
本文没有介绍数据库的函数、优化数据库、优化sql语句等深层次只是,有sql基础的自行绕过。。。。
select——查询
insert——插入
update——更新
delete——删除
from——从哪个表
where——查询条件
join——表连接
order by——排序
一、确保mysql安装成功,下图是mysql安装成功,并启动服务的标志:
1、计算机右键——管理——服务和应用程序——服务,查看mysql服务是否开启

二、打开navicat软件,将navicat与本地mysql服务连接:

点击connection——选择mysql,出现下图界面:

按照自己安装mysql中的信息,填好。出现下面的信息,证明连接成功:

三、创建数据库
首先打开一个执行sql语句的窗口:

执行创建数据库的sql语句

创建数据库的sql执行后,要刷新,在下图位置,右键,点击refresh

然后就能看见新建的sqltest数据库了
四、创建表的语句

首先打开sqltest数据库执行sql的窗口,注意,刚才打开执行sql的窗口是执行整个数据库的sql的窗口,现在我们要在sqltest数据库中执行sql语句,那么就要打开sqltest的sql窗口。
在上图红箭处Querries右键新建一个query,就打开了执行sql的窗口,
然后执行创建表的sql语句:
(主键外键的知识没有说明,,,)

利用软件添加一条数据:

五:insert语句:
打开执行sql语句的窗口,写入sql语句:

这条sql语句的意思是,向test表中,添加一条数据,id为2,name为test2,age为21,
刷新test表,就能查看到test表中多了一条刚刚insert进去的数据。
六、select语句
利用select语句查看表中的数据:

select * 意思是查询所有属性,
下面是带查询条件的sql语句:

这条sql语句的意思是,查询在test表中,id为1的数据,将这条数据的name属性和age属性查询出来。
七、update语句

八、delete语句

九、表连接查询,
现在我们建立两张表(我口述,读者按上文的方式,自己建表吧。。。),学生表student,和 教师teacher
表,表结构和其中的数据如图:
student表:id是主键(一条数据的标识,每条数据的主键肯定不同)
name:学生姓名
teacher_id:该学生所对应的教师的id(是个外键)

teacher表:
id:主键
name:姓名

现在我想知道”学生zhangsan的老师的名字是什么“。
在student表中,能够看出,学生zhangsan所对应的教师的id,也就是teacher_id是1,在teacher表中,id为1的教师的那么是teacher1,那么就能得出学生zhangsan的老师的名字是teacher1,
那么用sql怎么实现呢,这就是表的连接:

上面图中的sql语句就是一个最简单的表连接,能够看出就是最基本的select、from、where组合,
上图中的sql首先去看括号中的语句,也就是 select teacher_id from student where name='zhangsan'
这条语句能够查询出名字为zhangsan的学生的teacher_id ,我们能在表中找出值为1,那么剩余的也就是括号外的sql语句就变成了 select name from teacher where id=1; 这样,教师的名字就得到了
十、其他重要的sql语句,
select count(*) from test 查询test表中共有多少条数据
select count(*) from test where age=21 查询test表中age为21的数据一共有多少条,
select count(*) from test where age>21 查询test表中age大于21的数据一共有多少条,数据库中的int类型支持大于小于等比较。
select count(*) from test where age>21 and age<30 查询test表中age大于21并且小于30的数据一共有多少条
select * from test order by id desc 按id降序排序
——还有一种查询是查询从第几条到第几条,也就是分页查询, 不同的数据库sql语句不同,mysql数据库用的是limit语句,oracle用rownum语句。。。
还有很多查询方式,但都是select、from、where。。。。这些基础的组合。。。。。。
在数据库中自己会有一些运算的函数,比如求和的add函数等,还能自定义函数,函数就比较难了,,不再这基础篇写了。
sql语句知识很多,这里只是总结了最基础的一点点东西,其他的知识也有从这些基础知识中演化出来的,多加练习,会的东西会越来越多,
不同的数据库的sql是会有不同,但是一个数据库的sql会了,其他数据库的sql也就会了,所以在刚学sql时,没必要特意挑选数据库。
My Git : https://github.com/hejiawang
网友评论