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

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-10-09 08:33:40
Original
976 people have browsed it

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
);

Copy after login

1 Add column:

alter table table name add column name data type

alter table users add image blob;

Copy after login

2 Modify column:

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

alter table users modify sex char(2);

Copy after login

3 Delete column:

alter table table name drop column name

alter table users drop image;

Copy after login

4 Modify table name:

rename table table name to new table name

rename table users to user;

Copy after login

5 Modify the character set of the table:

alter table table name character set character set

alter table user character set gbk

Copy after login

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);

Copy after login

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

Copy after login

8 View table creation structure:

mysql> show create table users;

Copy after login

9 Delete table:

mysql> drop table test9;

Copy after login

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.

Related labels:
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 Issues
MySQL stops process
From 1970-01-01 08:00:00
0
0
0
Error when installing mysql on linux
From 1970-01-01 08:00:00
0
0
0
phpstudy cannot start mysql?
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template