MySQL table operations

Source: Internet
Author: User
Tags modifier

Editing directives using the editor
Edit
Create a table
CREATE TABLE Table name (
Field 1, type "width" constraint)
= = in the same table, field names cannot be the same
= = width and constraints optional
= = Field name and type are required
View Table
Show tables;
desc haha; View table structure
Show create table haha;
Show table status like ' haha ' \g
To modify a table:
Alter modify table name, modify field name Modify field data type modifier for field
Insert Inserts Data
Delete Deletes data
Update updates data
Modify Table Name
Rename table haha to Xixi;
ALTER TABLE HH rename Xixi;
Add New Field
ALTER TABLE t1 add math int (10);
ALTER TABLE T1 Add (Chinese int), 中文版 Int (10));
Modify field database type, modifier alter can only change database type cannot rename
ALTER TABLE T1 modify Chinese int (5) not null;
Modify name, data type, modifier
ALTER TABLE T1 change Chinese china int (6);
First after
ALTER TABLE t1 change 中文版 en int (6) after ID;
ALTER TABLE t1 modify en int (6) first;
Delete a field
ALTER table T1 drop en;
Inserting data (Adding records)
The string must be enclosed in quotation marks.
mysql> INSERT INTO T1 (Id,name,math,china) VALUES (1, "Wing", 80,90);
mysql> INSERT INTO T1 (Id,name,math,china) VALUES (2, "King", 70,100), (3, "Tom", 50,70);
mysql> INSERT INTO T1 values (4, "Xiaosan", 50,100);
mysql> INSERT INTO T1 (Id,math) values (5,70);
mysql> INSERT into T1 set id=6,math=65;
Update record
mysql> Update T1 set name= "Lili" where id=5;
Deleting records
mysql> Delete from T1 where id=6;
mysql> Delete from T1; Delete all records
Table replication: Key is not copied: primary key, foreign key, and index
Copy a table
Mysql> CREATE TABLE T10 (SELECT * from T3);
Mysql> CREATE TABLE T10 (select id,name from T3);

Duplicate table structure
mysql> CREATE TABLE t4 (SELECT * from T3 where 5=4);
mysql> CREATE table t4 (select Id,name from T3 where 5=4);

Copying records
mysql> INSERT INTO T3 select * from T10 where id=9;

Delete a table
mysql> drop table T1;

Delete a library
mysql> drop database GNU;

MySQL table operations

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.