Common commands for manipulating MYSQ databases __ Database

Source: Internet
Author: User
Query database in the database name: show databases;
Creating a database: Create DB name;
Select a library: Use library name (for example: use PHP;)
View all tables in a database: show tables;
Delete a database: Drop the name of the library (drop database PHP;)
Create a simple table:
CREATE TABLE Class (
Stu Int,
Name varchar (20),
Age int,
Area varchar (20)
);
CREATE TABLE Score (
Stu Int,
Name varchar (20),
ke varchar (10),
Fen int
);
Modify table Name: Rename table original name to new table name; (Rename table score to NewsCore;) Note: Database name cannot be changed
Deletes a table: drop table name; (drop table newscore;)
Query a table for more information: DESC table name; (desc class;)
Declaration Character set: set names UTF8;
Insert information: INSERT into table name (Id,name,title) VALUES (NULL, ' asdasd ', ' Asdsad ');
Modify Information: Update table name set Name= ' Aza de Azad ' where id=1; Change your order by what?

Delete Information: Delete from table name where id=2; Press What to delete your own set


Add a column to a table (the added column defaults to the last column in the table): ALTER TABLE name add Add field name character type; (For example: Alter TABLE class add age2 tinyint unsigned; )

You can use after to declare where the new column is.

If the added column is placed on the first ALTER TABLE name add column declaration, boy add ID int primary KEY auto_increment
Added after a column: Alter TABLE boy add age tinyint unsigned not null default flower;

modifying columns
ALTER TABLE name change is a modified column names declaration;
ALTER TABLE boy change height smallint not null default 180;

Delete Column
ALTER TABLE name drop column name;
ALTER TABLE boy drop ID;



Create a table with the same structure as another table: create table g2 like goods;
Clear a table: Truncate G2;

Five seed sentences are ordered: Where,group,having,order By,limit in this order

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.