Basic operation instruction MySQL

1.create database; // create a database database name

2.show databases; // see which databases are currently

3.use database name; // select a database operation

4.show tables; // see which tables are currently

5.desc table name; // View table structure

6.select * from table name; // insert the data view content

7.drop table table name; // Delete table

8.drop database database name // delete the database

 

9. create table table name (name 1 int, name 2 varchar (20), were 3 varchar (20), the name 4 int, were 5 date) default charset = utf8;

 

10. insert into table (a name, name 2, under 3, under 4, were 5) values ​​(1, "Millet", "M", 99, now ());

        // update modification

11, update table set field name = 'new content' where id = 1; // insert the modified content data

   @ Alter table table name change, formerly known as among the new types; // modify a column name

        列:alter table a change d yyc varchar(20);   

 

12. alter table name table add sub-segment type modification; // Modify Data Sheet

          // alter table yy add aa int (8); // add column

 

13. alter table table name drop column names // delete columns

          //alter table yy  drop aa;

 

14. @ select * from yy where Name 1 = 2; // * a single line of information inquiry wherein: represents all columns

         @ Select fname, field name 1, field name 2 from table; // query information in which one of

         @ Select * from table where field names like "the beginning of the value%"; // Fuzzy query

      // aggregate function

         @ Select count (*) from table name; // total

               // check out the current count the number of rows in the table () can also be put in field

         @ Select max (id) from table; // maximum

              // query the current table id column of one of the largest id

         @ Select min (id) from table; // minimum

              // query the current table id column minimum of an id

         @ Select avg (id) from table name; // average

             // query id average of the sum of the data in the current table    

         @ Select sum (id) from table name; // sum

            // query data in the current table id aggregate

          @ The id type of digital ordering

        @ Select field names id from table name order by field name id asc; // otder by ordering ase: Sort positive

        @ Select field names id from table name order by field name id desc; // otder by Sort desc: Reverse Order

]

 

 

15. delete from table where conditions; // delete data which is inserted a piece of content

         //delete from yy where 名1=2;

 

            @ Alter table m add primary key (a); // add to the original primary key table

            @ Alter table qq modify a integer auto_increment; // add primary key increment the original table

            @ Alter table qq modify a int; // delete the primary key increment

            @ Alter table qq drop primary key; // delete the primary key

               // add a primary key increment the first to add a primary key;

               // delete the primary key must first delete the primary key increment;

               

       @alter table ff modify title varchar (20); // not empty to become empty

 

16. // assertive (1 name) will not be repeated  

 

       A method, create table www (name 1 int primary key, name 2 varchar (20), were 3 varchar (20), the name 4 int, were 5 date) default charset = utf8;

     

       Method two, create table ww (name 1 int, name 2 varchar (20), were 3 varchar (20), the name 4 int, were 5 date, primary key ( `name 1`)) default charset = utf8; (` name 1 ') the wavy line is a single quote must be single quotes

                                                                (Name `1`) without the single quotation marks can also be (name 1)

 

17.     create table if not exists qqqq(名1 int,名2 varchar(20),名3 varchar(20),名4 int,名5 date,primary key(名1))default charset=utf8;

          // if not esists / said that if the same name, it will display a warning, you can not create!

                                 / If not directly create the same name

 

 

18.      create table www(名1 int primary key auto_increment,名2 varchar(20),名3 varchar(20),名4 int,名5 date)default charset=utf8;  

          insert into oo (name 2, under 3, under 4, were 5) values ​​( "Millet", "M", 99, now ());

 

                                                         // own name 1 (id) plus 1;

                                                         // increment can only be used for digital type

         insert into o (name 1 name 2, under 3, under 4, were 5) values ​​(2, "Millet", "M", 99, now ());

              2 // from the beginning

    

 

21.  create table ff(id int primary key auto_increment,title varchar(20) not null,author varchar(20) not null,date date)default charset=utf8;

             title varchar (20) // behind the increase not null

                      // let the field name is not empty

 

insert into // insert written

Numerical values ​​//

where  //

alter // change

change // change, transformation

person order  

 modify integer // modify integer

 not null

 

 

 Remove Columns

alter table table-name drop col-name;

Increase Column (single)

alter table table-name add col-name col-type comment 'xxx';

Increase column (multi-column)

alter table table-name add col-name col-type comment 'xxx', add col-name col-type(col-length) comment 'xxx';

Field and increases as the first column indicates the field is placed

alter table table-name add col-name col-type COMMENT 'sss' FIRST;

Field increased and the specified attribute is placed behind a particular column

alter table table-name add col-name col-type after col-name-1;

Use MODIFY a field type

alter table table-name modify column col-name col-type;

Modify the CHANGE field type

alter table table-name change col-name col-name col-type;

Use CHANGE modify the field name

alter table table-name change old-col-name new-col-name col-type;

Modified column type, length

alter table table-name change old-col-name new-col-name new-col-type;

 

View table column properties

show columns from table-name;

Modify the table name

rename table old-table-name to new-table-name;

DEFAULT NULL and set up for the field

alter table table-name modify col-name col-type not null default 100;

The default value of the modified field

alter table table-name alter col-name set default 10000;

Remove the default field values 

alter table table-name alter col-name drop default;

 

 
 

alter table table-name drop col-name;

Increase Column (single)

alter table table-name add col-name col-type comment 'xxx';

Increase column (multi-column)

alter table table-name add col-name col-type comment 'xxx', add col-name col-type(col-length) comment 'xxx';

Field and increases as the first column indicates the field is placed

alter table table-name add col-name col-type COMMENT 'sss' FIRST;

Field increased and the specified attribute is placed behind a particular column

alter table table-name add col-name col-type after col-name-1;

Use MODIFY a field type

alter table table-name modify column col-name col-type;

Modify the CHANGE field type

alter table table-name change col-name col-name col-type;

Use CHANGE modify the field name

alter table table-name change old-col-name new-col-name col-type;

Modified column type, length

alter table table-name change old-col-name new-col-name new-col-type;

 

View table column properties

show columns from table-name;

Modify the table name

rename table old-table-name to new-table-name;

DEFAULT NULL and set up for the field

alter table table-name modify col-name col-type not null default 100;

The default value of the modified field

alter table table-name alter col-name set default 10000;

Remove the default field values 

alter table table-name alter col-name drop default;

 

Guess you like

Origin www.cnblogs.com/yangyongchao/p/12159626.html