DDL_Operation Table_Create & Query

 table of Contents

  

                      2. Operation table

1.C (Create): Create

2.R (Retrieve): query

3.U(Update): modify

4. Copy table (insert one)

5.D (Delete): delete


 

                      2. Operation table

1.C (Create): Create

         ① Grammar:

                 create table 表名(

                                Column name 1 data type 1,

                                Column name 2 data type 2,

                                 ......

                                Column name n data type n

                                 );

                     Note: There is no need to add a comma (,) in the last column

    type of data:

       1. int: integer type age int,

       2.double: decimal type score double(5,2);

             ###Note (5, 2) Up to 5 decimal places to retain 2 decimal places

      3.date: date, including only year, month and day, yyyy-MM-dd

      4.datetime: date, including year, month, day, hour, minute and second yyyy-MM-dd HH:mm:ss

      5.timestamp: The time error type includes year, month, day, hour, minute and second yyyy-MM-dd HH:mm:ss

If you do not give this future field assignment, or assignment bit null, the system defaults to the current time, to automatically assign values

      6.varchar: string

              name varchar(20); The maximum name is 20 characters

              zhangsan 8 characters Zhang San 2

   

2.R (Retrieve): query

    Query all the table names in a database show tables;

        Query table structure desc table name;

 

Exercise: ###Create a table:

create table student(

id int,

name varchar(30),

age int,

score double(4,1),

birthday date,

insert_time timestamp

);

3.U(Update): modify

① Modify the table name

alter table table name rename to new table name;

② Modify the character set of the table

alter table table name character set character set name;

③Add a column

alter table table name add column name data type;

④ Modify the column name type

alter table table name change column name new column name new data type;

alter table table name modify column name new data type;

⑤Delete column

alter table table name drop column name;

 

 

 

4. Copy table (insert one)

create table table name like the name of the table being copied;

 

5.D (Delete): delete

drop table table name;

drop table if exists 表名;

Guess you like

Origin blog.csdn.net/Jason_LH1024/article/details/102760369