MySQL common statements

Source: Internet
Author: User

Modify Table:

Add field: alter table yyh_yp_managerrob add catid smallint (5)
, Add typeid smallint (5)
, Add areaid smallint (5)
, Add Title char (150)
, Add style char (5)
, Add thumb char (100)
, Add keywords char (40)
, Add description char (255)
, Add posids tinyint (1)
, Add URL char (100)
, Add listorder tinyint (3)
, Add status tinyint (2)
, Add userid mediumint (8)
, Add username char (20)
, Add inputtime int (10)
, Add updatetime int (10)
, Add searchid mediumint (8)
, Add islink tinyint (1)
, Add prefix char (20 );

Copy table structure: Create Table newtable (select * From oldtable)

Restore database:

Delete the original database first: drop database Database Name
Then create the database: creat database name
Then: Use Database Name
Then: source. SQL file path

Supplement:

The method for adding fields in MySQL is not complex. The following describes how to add and modify fields in MySQL. It is helpful for you to learn how to add fields in MySQL.

1. log on to the database
> Mysql-u root-P Database Name

2. query all data tables
> Show tables;

3. query table Field Information
> DESC table name;

4.1 Add Table Fields

Alter table Table1 add transactor varchar (10) Not NULL;

Alter table Table1 add ID int unsigned not null auto_increment primary key

. Modify the field type of a table and specify it as null or not
> Alter table table name change field Name field type [whether to allow non-null];
> Alter table table name Modify Field Name field type [whether to allow non-null];

> Alter table table name Modify Field Name field type [whether to allow non-null];

. Modify the field name of a table and specify it as null or not
> Alter table table name change field Original Name field New Name field type [whether to allow non-null

4.4 If you want to delete a field, run alter table mytable drop field name;

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.