mysql创建数据表代码_MYSQL 简单的建库操作代码
一、查询所有数据库
代码:show databases;
成功后如下图:
二、建立一个数据库
代码:create database test3;
成功后如下图:
三、连接数据库
代码:use test3;
成功后如下图:
四、建立库表
代码:create table test{
id int not null primary key auto_increment,
name varchar(30) not null
};
成功后显示:
五、显示表结构
代码:desc test;
成功后显示:
六、添加表内容
代码:insert into test (`name`)values(test);
成功后显示:
七、查询表内容
代码:select * from test;
成功后显示:
八、修改表内容
代码:update test set name = test2;
成功后显示:
九、删除表内容
代码:delete from test;
成功后显示:
十、添加表字段
代码:alter table test add password varchar(30) not null;
成功后显示:
十一、修改表字段名
代码:alter table test change name username varchar(50) not null;
成功后显示:
十二、修改表字段类型
代码:alter table test modify username char(30) not null;
成功后显示:
十三、删除表字段
代码:alter table test drop username;
成功后显示:
十四、删除数据库表
代码:drop table test;
成功后显示:
十五、删除数据库
代码:drop databases test3;
成功后显示:
十六:关闭数据库
代码:exit;
成功后退出命令行关闭。
一、查询所有数据库 代码:show databases; 成功后如下图: 二、建立一个数据库 代码:create database test3; 成功后如下图: 三、连接数据库 代码:use test3; 成功后如下图: 四、建立库表 代码:create table test{ id int not null primary key auto_increment, name varchar(30) not null }; 成功后显示: 五、显示表结构 代码:desc test; 成功后显示: 六、添加表内容 代码:insert into test (`name`)values(test); 成功后显示: 七、查询表内容 代码:select * from test; 成功后显示: 八、修改表内容 代码:update test set name = test2; 成功后显示: 九、删除表内容 代码:delete from test; 成功后显示: 十、添加表字段 代码:alter table test add password varchar(30) not null; 成功后显示: 十一、修改表字段名 代码:alter table test change name username varchar(50) not null; 成功后显示: 十二、修改表字段类型 代码:alter table test modify username char(30) not null; 成功后显示: 十三、删除表字段 代码:alter table test drop username; 成功后显示: 十四、删除数据库表 代码:drop table test; 成功后显示: 十五、删除数据库 代码:drop databases test3; 成功后显示: 十六:关闭数据库 代码:exit; 成功后退出命令行关闭。