mysql 操作表结构
时间:2021-07-01 10:21:17
帮助过:24人阅读
显示所有的数据库
create database demo;
--创建了一个demo名的数据库
drop database demo;
--删除这个数据库
use demo;
--定位demo数据库,进入到里面
show tables; --显示所有的表
--下面是创建一个表
DROP TABLE IF EXISTS `my_column`;
CREATE TABLE `my_column` (
`id` int(
10) unsigned
NOT NULL AUTO_INCREMENT COMMENT
‘商品栏目id主建‘,
`pid` int(
10)
NOT NULL DEFAULT ‘0‘ COMMENT
‘父级栏目‘,
`uid` smallint(
5)
NOT NULL COMMENT
‘用户id‘,
`title` char(
50)
NOT NULL COMMENT
‘栏目名‘,
`img` varchar(
255)
DEFAULT NULL,
`keyword` char(
255)
DEFAULT NULL COMMENT
‘栏目关键词‘,
`description` char(
255)
DEFAULT NULL COMMENT
‘栏目描述‘,
`create_time` int(
11) unsigned
NOT NULL,
`sort` char(
5)
NOT NULL DEFAULT ‘50‘ COMMENT
‘排序‘,
`status` smallint(
3)
NOT NULL DEFAULT ‘1‘ COMMENT
‘状态‘,
PRIMARY KEY (`id`,`uid`)
) ENGINE=InnoDB AUTO_INCREMENT
=30 DEFAULT CHARSET
=utf8;
---修改表结构
mysql> desc z_test;
+-------+------------------+------+-----+---------+----------------+
| Field
| Type
| Null | Key | Default | Extra
|
+-------+------------------+------+-----+---------+----------------+
| id
| int(
11) unsigned
| NO
| PRI
| NULL | auto_increment
|
| name
| varchar(
255)
| NO
| UNI
| NULL | |
| age
| int(
11)
| NO
| | NULL | |
| info
| varchar(
255)
| NO
| | NULL | |
+-------+------------------+------+-----+---------+----------------+
4 rows
in set
mysql> alter table z_test
add content
text(
255) after age;
Query OK, 0 rows affected
Records: 0 Duplicates:
0 Warnings:
0
mysql> desc z_test;
+---------+------------------+------+-----+---------+----------------+
| Field
| Type
| Null | Key | Default | Extra
|
+---------+------------------+------+-----+---------+----------------+
| id
| int(
11) unsigned
| NO
| PRI
| NULL | auto_increment
|
| name
| varchar(
255)
| NO
| UNI
| NULL | |
| age
| int(
11)
| NO
| | NULL | |
| content
| text | YES
| | NULL | |
| info
| varchar(
255)
| NO
| | NULL | |
+---------+------------------+------+-----+---------+----------------+
--修改字段属性
alter table z_test modify content
varchar(
50);
--修改表中莫个列的名称,把age改为phone
alter table z_test change age phone
int(
11)
not null;
--删除列
alter table z_test
drop content;
差不多了。先这样,基本上就这样啦!!!
mysql 操作表结构
标签:class 图形化 status com warning 记忆 ted create field