最近在研究数据库,将自己的个人网站优化,下面对数据库的黑框操作做个总结

多说两句,其实现在的可视化工具已经做得很好了,便捷快速,推荐一个Navicat for MySQL,真的很好用。

话说回来,对于数据库,我们还是要了解一下黑框操作的!

1.创建数据库
  show  databases;
  create  database content;

MySQL 命令操作

MySQL 命令操作

 


2.定位数据库
  use content;   查看当前有没有表   show  tables;

MySQL 命令操作
3.创建表
  create table user(
    id int not null auto_increment primary key,
    name varchar(50) not null
    );
 create table user(
    id int not null auto_increment,
    name varchar(50) not null,
    primary key(id)
    );

MySQL 命令操作
 //创建另一张表  带主键和外键
create table list(
id int not null auto_increment,
listid int not null,
primary key(id),
foreign key (listid) references user ('id')
);
alter table list add foreign key ('listid') references user ('id');
4.删除表
    drop table data;

MySQL 命令操作
5.自增列必须是主键  并且主键不能为空  主键比一定是自增   唯一键(值不能重复可以为null)
6.查找 (简单查询  子查询  多表查询)
简单查询 :select * from user;
    select id,name,sex,age from user;
    如果想给表的列起个别名
    select id as '序号',name as '姓名' from user;
简单查询里面的条件查询:
    select * from user where id=2;
    select * from user where id=2 and name='张三';
子查询: select * from blog where id in (select userid from user where id=2);
多表查询:
    select user.id,blog.content,list.times from user,blog,list where user.id=2 and list.id=2;
7.增加
insert into user vlaues(null,'',1,2,3);
insert into user(name,sex,age)
values
('','',1);
8.修改
update user set name="张三" where id=2;
9.删除
delete from user  where id=2;
多行删除
delete from user  where id in(select id from user);

相关文章:

  • 2021-06-09
  • 2021-05-29
  • 2021-09-25
  • 2021-11-11
  • 2021-05-08
猜你喜欢
  • 2021-07-17
  • 2021-10-26
  • 2021-07-26
  • 2021-11-05
  • 2021-04-30
  • 2022-01-07
  • 2022-01-07
相关资源
相似解决方案