How to create, delete, and modify tables for Mysql learning notes _mysql

Source: Internet
Author: User
Tags mysql index

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:

mysql> drop table Test9;

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.