Basic operation of tables in MySQL

Source: Internet
Author: User

basic creation of a table

    create TABLE userinfo (
        username char (5) Not NULL,
         pwd VARCHAR (
         age

Sex SMALLINT(100)
)

The blue representation is the keyword in SQL CREATE TABLE userinfo is the table name and the field is created in such a way as username CHAR(5), c11>username The data type of the field that represents the second bit after the field name is the field length in parentheses, not NULL


Renaming a table

RENAME TABLE ' user ' to NewUser

Change the user table to be named NewUser table


Deletion of tables

DROP TABLE newuser

Remove the name of the user table from the database





Add a new field to the table

ALTER TABLE userinfo ADD Hobby char (a) not NULL

Add a userinfo table with a new field for hobby and also set the type of the data





Renaming columns in a table

ALTER TABLE UserInfo Change username newname VARCHAR (+)

Update the username field named UserInfo table to the new field name for NewName and specify the data type of the field





Basic operation of tables in MySQL

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.