整理收集了一些MySQL数据库常用的命令,对初学者还是大有帮助的。
references users(id) on delete set null;
------------------------------------------------------------------------
--3. 向users表中插入数据,同时插入多条
insert into users (id,nikename,password,address) values (1,'lyh1','1234',null),(10,'lyh22','4321','湖北武汉'),(null,'lyh333','5678', '北京海淀');
--4. 向article中插入三条数据
insert into articles (id,content,userid) values (2,'hahahahahaha',11),(null,'xixixixixix',10),(13,'aiaiaiaiaiaiaiaiaiaiaiaia',1),(14,'hohoahaoaoooooooooo',10);
--5. 进行多表查询,选择users表中ID=10的用户发布的所有留言及该用户的所有信息
select articles.id,articles.content,users.* from users,articles where users.id=10 and articles.userid=users.id order by articles.id desc;
--6. 查看数据库引擎类型
show create table users;
--7. 修改数据库引擎类型
alter table users engine=MyISAM; ---因为users表中ID被设置成外键,执行此句会出错
--8. 同表查询,已知一个条件的情况下.查询ID号大于用户lyh1的ID号的所有用户
select a.id,a.nikename,a.address from users a,users b where b.nikename='lyh1' and a.id>b.id;
------也可写成
select id,nikename,address from users where id>(select id from users where nikename='lyh1');
9. 显示年龄比领导还大的员工:
select a.name from users a,users b where a.managerid=b.id and a.age>b.age;
查询编号为2的发帖人: 先查articles表,得到发帖人的编号,再根据编号查users得到的用户名。
接着用关联查询.
select * from articles,users得到笛卡儿积,再加order by articles.id以便观察
使用select * from articles,users where articles.id=2 筛选出2号帖子与每个用户的组合记录
再使用select * from articles,users where articles.id=2 and articles.userid=users.id选出users.id等于2号帖的发帖人id的记录.
只取用户名:select user where user.id=(select userid from articles where article.id =2)
找出年龄比小王还大的人:假设小王是28岁,先想找出年龄大于28的人
select * from users where age>(select age from users where name='xiaowang');
*****要查询的记录需要参照表里面的其他记录:
select a.name from users a,users b where b.name='xiaowang' and a.age>b.age
表里的每个用户都想pk一下.select a.nickname,b.nickname from users a,users b where a.id>b.id ;
更保险的语句:select a.nickname,b.nickname from (select * from users order by id) a,(se
lect * from users order by id) b where a.id>b.id ;
再查询某个人发的所有帖子.
select b.* from articles a , articles b where a.id=2 and a.userid=b.userid
MySQL数据库常用命令_IT/计算机_专业资料。在命令行连接MySQL数据库格式: mysql -h主机地址 -u用户名 -p用户密码 数据库 1、连接到本机上的MySQL。 首先在...
MYSQL数据库常用命令_IT/计算机_专业资料。MYSQL数据库常用命令1:使用 SHOW 语句找出在服务器上当前存在什么数据库: mysql> SHOW DATABASES; 2:创建一个数据库 ...
MySql常用命令大全及示例_计算机软件及应用_IT/计算机_专业资料。出处:http://...4.2 显示数据库命令:show databases (注意:最后有个 s) mysql> show ...
1、MySQL常用命令 create database name; 创建数据库 use databasename; 选择数据库 drop database name 直接删除数据库,不提醒 show tables; 显示表 describe table...
并对所有数据库有查 询,插入,修改,删除的权限.首先用以 root 用户连入 mysql,然后键入以下命令: grant select,insert,update,delete on *.* to user1@...
Mysql 常用命令 show databases; 显示数据库 create database name; 创建数据库 use databasename; 选择数据库 drop database name 直接删除数据库,不提醒 show ...
MySQL数据库常用命令大全_计算机软件及应用_IT/计算机_专业资料。一、连接 MySQL 格式: mysql -h 主机地址 -u 用户名 -p 用户密码 1、例1:连接到本机上的...
以下的文章主要是向大家介绍的是 MySQL 常用命令的总结,这篇文章对于 MySQL 数据库 方面的新手是一个很好的学习资料 以下就是具体内容的描述,希望在你今后的学习...
Mysql常用命令行大全Mysql常用命令行大全隐藏>> Mysql常用命令行大全 第一招、...增加一个用户user1密码为password1,让其可以在本机上登录, 并对所有数据库有...
热门文档