Home > Database > Mysql Tutorial > body text

How to add column data in mysql

little bottle
Release: 2019-05-29 16:25:34
Original
9943 people have browsed it

How to add column data in mysql

How to add column data in mysql

For an already established table, as the requirements change, you will need to add a column to this table. Of course, you can create a new table to establish a relationship to meet your needs.

But for the problem of adding only one column, you can do the following:

ALTER ...  ADD COLUMN ....
Copy after login

1. Add a new column to the last column of the table

ALTER TABLE `tbname`
ADD COLUMN `state` TINYINT(2) NOT NULL DEFAULT '0' COMMENT '0为添加1为编辑'
Copy after login

2. Add a new column at the specified position

ALTER TABLE `tbname`
ADD COLUMN `state` TINYINT(2) NOT NULL DEFAULT '0' COMMENT '0为添加1为编辑' AFTER `column_name`;
Copy after login

3. Add a new column in the first column

ALTER TABLE `tbname`
ADD COLUMN `state` TINYINT(2) NOT NULL DEFAULT '0' COMMENT '0为添加1为编辑' FIRST;
Copy after login

The above is the detailed content of How to add column data in mysql. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template