mysql数据库基本操作(一)

来源:互联网 发布:服务器提供商 知乎 编辑:程序博客网 时间:2024/05/30 23:11

创建数据库:create database test;
查看数据库:show databases;
使用数据库:use test;
这里写图片描述
查看当前使用的数据库:select database();
这里写图片描述
删除数据库:drop database test;(慎用!!!!!!!!!!!!!!)

创建表:create table people(id int primary key auto_increment,name varchar(20) not null,age int(8) not null,brithday datetime);
这里写图片描述

查看表:show tables;
查看表结构:desc people;
这里写图片描述

向表中插入一列:alter table people add handsome bool;
查看表结构:desc people;
这里写图片描述

修改表中字段属性:alter table people modify age int(4);
查看表结构:desc people;
这里写图片描述

删除列:alter table people drop column handsome;

修改表名:rename table people to information;
查看表:show tables;
这里写图片描述

复制表:create table copy_information select * from information;
查看表:show tables;
这里写图片描述

向表中插入数据:insert into information values(1,’张三’,23,’1993-04-12’,True);
查看表中内容:select * from information;
这里写图片描述

向表中添加多条数据,查看表中内容:select * from information;
这里写图片描述

删除表中数据:delete from information where name = ‘李四’;
查看表中内容:select * from information;
这里写图片描述

修改表中数据内容:update information set name=’叶良成’ where name=’李三’;
查看表中内容:select * from information;
这里写图片描述

创建表时候添加默认注释
CREATE TABLE test(
id int primary key auto_increment comment ‘主键自增’,
name varchar(200) comment ‘姓名’,
) comment=’表注释’;

原创粉丝点击