MySQL-operation table

Source: Internet
Author: User

1. Create a table

CREATE TABLE  [notnull][notnull],);
Example:
CREATE TABLE Student (
Sno Char (7) NOT null primary key,
Sname varchar (TEN) is not NULL,
Ssex char (2),
Sage integer
)

Data type char (fixed-length character): a space is usually used to populate an insufficient number of characters. Do not use fixed-length characters to hold variable lengths of data, such as names, which could result in wasted space and an accurate comparison of different data.

VARCHAR (variable length character)

2. Modify the table

You can add columns, delete columns, modify column definitions, add and remove constraints.

Alter Tabletable_name[Modify] [Column column_name] [datatype|null NOT NULL] [Restrict|cascade]                 [Drop] [constraint constraint_name]                 [Add] [column] columnDefinition

3. Create another table from an existing table

Use the combination of the CREATE TABLE and SELECT statements to copy an existing table.

Create Table  as Select [*|column1, Column2]  from [where]

4. Delete a table

Drop Table [restrict|cascade]

If the Restrict option is used and the table is referenced by the view or constraint, the DROP statement returns an error. When the Cascade option is used, the delete operation executes successfully and all referenced views and constraints are deleted.

===================================================================================================

1. Command line login local MySQL

Mysql-h localhost-u username-p Password

2. Tell MySQL which database we want to use:

Use MyDB;

3. List all tables for this DB:

Show tables;

4. List all fields and properties of the table (describe):

DESC table_name;

MySQL-operation table

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.