mysql数据库基本操作(一)

xiaoxiao2021-02-28  64

创建数据库: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=’表注释’;

转载请注明原文地址: https://www.6miu.com/read-22541.html

最新回复(0)