Article From:https://www.cnblogs.com/sunhao1987/p/9122234.html

1.Display all current databases

show databases;

2Create a database

create database ceshi;

3Entry (use) database

use ceshi;

4Display the table in the database

show tables;

Note: data type

           Digital type:

                   Integer: 8 times tinyint 1 bytes 2

                               int      464 times square of bytes 2

                         decimal(m,d) The total length of a fixed-point m number

                                                                  ddecimals

                                decimal(5,2)1.2896-1.29

                                                           999.123-999.12

                      Character:

                            char(255)  Fixed length character

                            varchar(255) Variable length character

                          Date and time

                                  datetime 8Bytes 2018-06-01 09:05:01

                           Primary key: p’rimary key

                            Self growth: auto_increment

                             Non empty: not null

                            Default value: default value

5,Build a table

          It is necessary to indicate that the data type is not empty

          Each table is set up with a primary key

create table Myclass(

           id int(4)not null primary key auto_increment,

           name char(20) not null,

           sex int(4) not null default”0″,

           degree  decimal(16,2)

            );

6, View table structure

  desc  myclass;

===================

show= display

create= create

database=data base

7insert data

insert into myclass values(’ ’,’Zhang three ‘,’, 98.5);

8View the data in the table

select*from myclass;

9Modify information

 update myclass set name = ‘Zhang three ‘where id = 1;

10Delete information

   delete from myclass where id = 1;

=============================================

alter table myclass + Sentence

1 Modifying the table name

rename as newcl;

2Add field

 add age int(4)not null;

add pid int(4) not null first;

add selfsm char(255) not null after age;

3Modify the name and type of the field

change age newage char(20);

4Modify the type of a field

modify column newage int(4);

5Add default values – if there is a default value, delete it first and add it again.

alter column newage drop default;

alter column newage set default  18;

6Delete field

drop  id;

7Add primary key

add primary key(Field name);

8drop primary key

drop primary key;

9Delete table

drop table newcl;

show tables;

10Delete database

drop database ceshi;

show databases;

Link of this Article: 6.1 database MySQL base

Leave a Reply

Your email address will not be published. Required fields are marked *