Summary of commonly used SQL in MySQL operation tables

Summary of commonly used SQL in MySQL operation tables

1. View the types of fields in the table

describe table_name
desc table_name

2. Rename the table

rename table original table name to new table name;

3. Solve the mysql query timeout

select /+QUERY_TIMEOUT(150000000000)/ * from table_name
SQL plus +/+QUERY_TIMEOUT(150000000000)/

4. View the index

show index from table_name

5. Create a normal index

create index index name on table name (field name)
alter table table name add index index name (field name)

6. Create a joint index

alter table table name add index index name (field name 1, field name 2)

7. Create a primary key index

alter table table name add primary key (field name)

8. Delete the index

drop index index_name on table_name
alter table table name drop index index name

9. Create a unique index

create unique index index name on table name (field name);

10. Group by has the function of removing duplicates

11. Try to use SQL to solve problems that can be solved with SQL statements instead of writing code.

12. Delete table operation

drop table if exists stu;

13. Use alter to add fields to the table

ALTER TABLE [table name] ADD [column name] [type]
alter table table1 add transactor varchar(10) not Null;

14. Use alter to delete table fields

ALTER TABLE [table name] DROP [column name]

15. Use alter to modify column names

ALTER TABLE [table name] CHANGE [column name] [new name]

16. Modify the table name

ALTER TABLE tbl_name rename new_tbl_name;

17. Use explain to analyze the SQL statement of the query and check the query efficiency of SQL.

explain select statementdesc select statement

18. When creating a table, be sure to add comments to each field, using the comment 'comment'

19. For MySQL database tables, the query efficiency and speed of the primary key are greater than those of the ordinary index.

20. The index created today will not take effect until tomorrow.

21. Process large amounts of data using partitioning, table sharding, and database sharding operations.

This is the end of this article about the commonly used SQL for operating tables in MySQL. For more relevant content about commonly used SQL for operating tables in MySQL, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • A brief discussion of 30 common methods for optimizing SQL query in MySQL
  • A collection of commonly used MySQL commands [absolutely essential]
  • Summary of commonly used MySQL functions (sharing)
  • Common methods for MYSQL optimization
  • Detailed introduction to 5 commonly used MySQL database management tools
  • Organize the commonly used MySql query statements (23 types)
  • Common command line statements for mysql
  • Summary of common commands for MySQL database backup and restore
  • MySQL common commands
  • MySql common query command operation list

<<:  Detailed troubleshooting of docker.service startup errors

>>:  Native JS implements a very good-looking counter

Recommend

Detailed explanation of Vue router routing guard

Table of contents 1. Global beforeEach 1. Global ...

Detailed explanation of triangle drawing and clever application examples in CSS

lead Some common triangles on web pages can be dr...

How to hide elements on the Web and their advantages and disadvantages

Example source code: https://codepen.io/shadeed/p...

Differences between this keyword in NodeJS and browsers

Preface Anyone who has learned JavaScript must be...

MySQL dual-master (master-master) architecture configuration solution

In enterprises, database high availability has al...

Detailed explanation of various HTTP return status codes

When a request is sent to your server to display ...

Use of CSS3's focus-within selector

Pseudo-elements and pseudo-classes Speaking of th...

Linux uses shell scripts to regularly delete historical log files

1. Tools directory file structure [root@www tools...

Zabbix monitoring docker application configuration

The application of containers is becoming more an...

JavaScript Canvas implements Tic-Tac-Toe game

This article shares the specific code of JavaScri...

Detailed explanation of Vue3's sandbox mechanism

Table of contents Preface Browser compiled versio...

CocosCreator Getting Started Tutorial: Making Your First Game with TS

Table of contents premise TypeScript vs JavaScrip...

Detailed explanation of creating and calling MySQL stored procedures

Table of contents Preface Stored Procedure: 1. Cr...

Nginx server https configuration method example

Linux: Linux version 3.10.0-123.9.3.el7.x86_64 Ng...