This article illustrates the method of creating, deleting, and modifying a table for MySQL learning notes. Share to everyone for your reference, specific as follows:
To create a table:
CREATE TABLE users (
ID int,
name varchar (),
sex bit (1),
birthday date,
entry_date date,
job varchar (),
salary float,
resume text
);
1 Add Columns:
ALTER TABLE name add column name data type
ALTER TABLE users add image blob;
2 Modifying columns:
ALTER TABLE name modify column name new data type (data length size)
ALTER TABLE users modify sex char (2);
3 Delete columns:
ALTER TABLE name drop column name
ALTER TABLE users drop image;
4 Modify Table Name:
Rename table name to new table name
Rename table users to user;
5 Modify the table's character set:
ALTER TABLE name Character Set character set
ALTER TABLE user Character set GBK
6 Modification Column Name:
ALTER 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 (one) | 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:
More information about MySQL interested readers can view the site topics: "MySQL Index operation skills Summary", "MySQL Log Operation skills Encyclopedia", "MySQL Transaction operation skills Summary", "MySQL stored process skills encyclopedia", "MySQL database lock related skills summary" and " MySQL common function Big Summary "
I hope this article will help you with the MySQL database meter.