MySQL study notes 03 [CRUD operations of database tables, basic operations recorded in database tables, client graphical interface tool SQLyog]

  • MySQL Document-Dark Horse Programmer (Tencent Weiyun): https://share.weiyun.com/RaCdIwas
  • 1-MySQL foundation.pdf, 2-MySQL constraints and design.pdf, 3-MySQL multi-table query and transaction operation.pdf
  1. MySQL study notes 01 [database concept, MySQL installation and use] [day01]
  2. MySQL study notes 02 [SQL basic concepts and general grammar, database CRUD operations] [day01]
  3. MySQL study notes 03 [CRUD operations of database tables, basic operations recorded in database tables, client-side graphical interface tool SQLyog] [day01]

  4. MySQL study notes 04 [database query operations, table constraints] [day01, day02]

  5. MySQL study notes 05 [multi-table operation, three paradigms, database backup and restore] [day02]

  6. MySQL study notes 06 [multi-table query, sub-query, multi-table query exercises] [day03]

  7. MySQL study notes 07 [transaction, user management and authority management] [day03]

table of Contents

05 CRUD operations on database tables

DDL_operation table_query

DDL_Operation Table_Create

Copy table

DDL_Operation Table_Modify

Modify the table name: alter table table name rename to the 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 column name type: alter table table name change column name new column name new data type;

Delete column: alter table table name drop column name;

DDL_Operation Table_Delete

Client graphical interface tool SQLyog

Use SQLyog to log in to the database

Use SQLyog to operate the database

06 Basic operations recorded in database tables

DML_Add data

DML_Delete data

DML_Modify data


05 CRUD operations on database tables

DDL_operation table_query

R(Retrieve): query

  • Query all the table names in a database: show tables;
  • Query table structure: desc table name; (description)

DDL_Operation Table_Create

Syntax:
   create table table name (
      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

Data field type

  1. int: integer type [age int]
  2. double: decimal type [score double(5, 2) up to 5 digits, 2 decimal places are reserved]
  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: Timestamp type, including year, month, day, hour, minute and second, yyyy-MM-dd HH:mm:ss [If you do not assign a value to this field in the future, or assign it to null, the current system time will be used by default to automatically assign the value.
  6. varchar: string [name varchar(20): maximum name is 20 characters; zhangsan 8 characters, Zhang San 2 characters]

Create table

create table student(
    id int,
    name varchar(32),
    age int,
    score double(4,1),
    birthday date,
    insert_time timestamp
);

Copy table

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

DDL_Operation Table_Modify

U(Update): modify

  1. Modify the table name: alter table table name rename to the new table name;
  2. Modify the character set of the table: alter table table name character set character set name;
  3. Add a column: alter table table name add column name data type;
  4. Modify 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;
  5. Delete column: alter table table name drop column name;

Modify the table name: alter table table name rename to the 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 column name type: alter table table name change column name new column name new data type;

Delete column: alter table table name drop column name;

DDL_Operation Table_Delete

D(Delete): delete

  • drop table table name;
  • drop table  if exists 表名 ;

Client graphical interface tool SQLyog

SQLyog graphical tool-client

SQLyog is a simple, efficient and powerful graphical MySQL database management tool produced by the well-known Webyog company in the industry. Using SQLyog can quickly and intuitively allow you to maintain a remote MySQL database through the network from any corner of the world.

Use SQLyog to log in to the database

  

Use SQLyog to operate the database

06 Basic operations recorded in database tables

DML_Add data

Syntax: insert into table name (column name 1, column name 2, ... column name n) values ​​(value 1, value 2, ... value n);
Note:

  1. The column name and value should correspond one to one.
  2. If the column name is not defined after the table name, the default value will be added to all columns [insert into table name values ​​(value 1, value 2, ... value n);]
  3. Except for numeric types, other types need to be enclosed in quotation marks (both single and double).

DML_Delete data

Syntax: delete from table name [where condition]

note:

  1. If no conditions are added, all records in the table are deleted.
  2. If you want to delete all records
    1. delete from table name; - not recommended. There will be as many delete operations as there are records (low efficiency).
    2. TRUNCATE TABLE table name; - (recommended, more efficient) delete the table first, and then create the same table.

DML_Modify data

Syntax: update table name set column name 1 = value 1, column name 2 = value 2,... [where condition];

Note: If no conditions are added, all records in the table will be modified.

Guess you like

Origin blog.csdn.net/weixin_44949135/article/details/113524673
Recommended