Home >Database >Mysql Tutorial >MySQL study notes: methods to create, delete, and modify tables_MySQL

MySQL study notes: methods to create, delete, and modify tables_MySQL

WBOY
WBOYOriginal
2016-10-09 08:33:40933browse

The examples in this article describe the methods of creating, deleting, and modifying tables in MySQL study notes. Share it with everyone for your reference, the details are as follows:

Create table:

create table users(
  id int,
  name varchar(64),
  sex bit(1),
  birthday date,
  Entry_date date,
  job varchar(32),
  salary float,
  resume text
);

1 Add column:

alter table table name add column name data type

alter table users add image blob;

2 Modify column:

alter table table name modify column name new data type (data length)

alter table users modify sex char(2);

3 Delete column:

alter table table name drop column name

alter table users drop image;

4 Modify table name:

rename table table name to new table name

rename table users to user;

5 Modify the character set of the table:

alter table table name character set character set

alter table user character set gbk

6 Modify column name:

alter table table name change column original column name new column name type

alter table users change column sex sexy varchar(2);

7 View table structure:

mysql> describe users;
+------------+-------------+------+-----+---------+-------+
| Field   | Type    | Null | Key | Default | Extra |
+------------+-------------+------+-----+---------+-------+
| id     | int(11)   | YES |   | NULL  |    |
| name    | varchar(64) | YES |   | NULL  |    |
| sex    | bit(1)   | YES |   | NULL  |    |
| birthday  | date    | YES |   | NULL  |    |
| Entry_date | date    | YES |   | NULL  |    |
| job    | varchar(32) | YES |   | NULL  |    |
| salary   | float    | YES |   | NULL  |    |
| resume   | text    | YES |   | NULL  |    |

8 View table creation structure:

mysql> show create table users;

9 Delete table:

mysql> drop table test9;

Readers who are interested in more MySQL-related content can check out the special topics on this site: "Summary of MySQL Index Operation Skills", "Comprehensive Collection of MySQL Log Operation Skills", "Summary of MySQL Transaction Operation Skills", "Comprehensive Collection of MySQL Stored Procedure Skills", " Summary of MySQL database lock related skills" and "Summary of commonly used MySQL functions"

I hope this article will be helpful to everyone’s MySQL database planning.

Statement:
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