Get the App
SLTechnology News&Howtos  ›  Database  › 

Summary of sql basic sentences in Mysql Database

Shulou Source: shulou.com Published: 2022-06-01 04:36:49 10月04日 Update

This paper gives an example to describe the basic sql statements of Mysql database. Share with you for your reference, the details are as follows:

SQL basic statement

1. Login, exit and shortcut keys:

(1) Shortcut keys

-quickly get back to the beginning of the line.

Ctrl + a

-go back to the end of the line

Ctrl + e

-clear the screen

Ctrl + l

-the end.

Ctrl + c + spaces

(2) connect to the database:

-display password

Mysql-uroot-pmysql

-do not display password

Mysql-uroot-p enter password

(3) exit the database:

Quit/exit/ctrl + d

(4) part of the order:

-display the database version

Select version ()

-display time

Select now ()

two。 Database operations:

(1) create:

-create a database

Create database database name charset=utf8

(2) use:

-use the database

Use database name

(3) View:

-View the database currently in use

Select database ()

-View all databases

Show databases

-View create database statements

Show create database database name

(4) Delete:

-Delete the database

Drop database database name

(5) backup and recovery of database (understanding):

-backup

Mysqldump-uroot-p database name > xxx.sql

-recovery

Mysql-uroot-p New Database name < xxx.sql

3. Table structure operation:

(1) View:

-View all tables in the current database

Show tables

-View the table structure

Desc table name

-View table creation statements

Show create table table name

(2) create:

-create a table

Create table table name (field name data type constraint,... .. …… .. ); (auto_increment: automatic growth)

(3) modify:

-add a field

Alter table table name add field name type constraint

-modify fields (do not rename)

Alter table table name modify field name type constraint

-modify the field (rename)

Alter table table name change old field name new field name type constraint

-delete field

Alter table table name drop field name

(4) Delete:

-delete the table:

Drop table table name

4. Table data manipulation:

(1) View:

-View all fields

Select * from table name

-View the specified field

Select field name, field name from table name

-View by condition

Select * from table name where condition

-alias the field to view it.

Select field name as alias from table name

(2) increase:

-insert all columns

Insert into table name values (record)

-partial insertion

Insert into table name (field name) values (record)

-Multi-line insertion

Insert into table name values (record 1), (record 2)...

(3) Delete:

-physical deletion

Delete from table name where condition

-logical deletion

Alter table table name add delete information field name bit dafault 0; update table name set delete information field name = 1 where condition

(4) to modify:

-modify all

Update table name set modification information

-modify according to conditions

Update table name set modification information where condition

More readers who are interested in MySQL-related content can check out this site topic: "MySQL query skills Collection", "MySQL Common function Summary", "MySQL Log Operation skills Collection", "MySQL transaction Operation skills Summary", "MySQL stored procedure skills Collection" and "MySQL Database Lock related skills Summary"

It is hoped that what is described in this article will be helpful to everyone's MySQL database design.

Tags: Data databases fields conditions techniques statements information types encyclopedia passwords aliases backups shortcuts structures sections topics transactions interests contents functions Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology MariaDB Shulou Information Shulou Tech Info Redmi