MySQL database basic syntax and operation

MySQL database basic syntax and operation

MySQL database basic syntax

DDL Operations

Create database syntax: create database database name;
View all database syntax: show databases;
Switch (use) database syntax: use + database name;
Create a table syntax: create table table name (
Field Name 1 Field Type,
Field Name 2 Field Type,
Field Name 3 Field Type,
…… ……
);
View all tables in the database: Show tables;
View the structure syntax of the table: desc table name;
Add field syntax: alter table table name add field name field type Delete field syntax: alter table table name drop field name Modify table name syntax: rename table old table name to new table name Modify field type syntax: alter table table name modify field name new field type Field rename syntax: alter table table name change old field name new field name field type

DML Operations

Insert data syntax: insert into table name (field name) value (content)
Deleting data syntax: Delete from table name where condition Modifying data syntax: update table name set field = modified content where (restriction condition)
View data syntax: select field name from table name where condition delete table syntax: drop table table name;
truncate table table name;
Deleting a Database
drop database library name;
Note:
(1) Delete only deletes the records inserted into the table but does not delete the records. (2) Truncate deletes both the data and the records, which is equivalent to dropping the table and then creating it.

constraint

Primary key constraint features: uniqueness, non-nullability. Setting primary key and auto-increment primary key: When creating a table, add the primary key after the field to be set as the primary key.
Auto-increment: When creating a table, add auto_increment after the field to be set to auto-increment.
Not null constraint: cannot be empty. Add not null in the constraint position.
Foreign key constraints:
To create a foreign key based on the primary key of the main table, add the foreign key after the field definition.
Constraint (foreign key name) foreign key (the field being constrained) references primary table name (the field constrained by the outside world)
The field used as a constraint in the main table must be the primary key of the table

DQL Operations

Basic query query all:
select * from table name to query the data of the specified column:
Select column name 1, column name 2... from table name Write which column(s) to check Which column to check in the current database View tables in other databases
Show tables in database name View the data in the table of the non-current database
Select column name from bank.user;
Where query condition relational operator: > < = != >= <=
Interval: between A and B [A,B]
AND && and
or || : or
not: non-negation
Is null: is empty
is not null : not empty
in what contains fuzzy query
Like like wildcard
_: Any character
%: any number

This is the end of this article about the basic syntax and operations of MySQL database. For more relevant MySQL database syntax content, please search for previous articles on 123WORDPRESS.COM or continue to browse the related articles below. I hope everyone will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Detailed explanation of database language classification DDL, DCL, DML
  • MSSQL monitors database DDL operations (create, modify, delete stored procedures, create, modify, delete tables, etc.)
  • Use of MySQL DDL statements
  • Summary of common Mysql DDL operations
  • MySQL learning to create and operate databases and table DDL for beginners

<<:  Three ways to draw a heart shape with CSS

>>:  Web Design Experience

Recommend

How to deploy Oracle using Docker on Mac

How to deploy Oracle using Docker on Mac First in...

How to use HTML+CSS to create TG-vision homepage

This time we use HTML+CSS layout to make a prelim...

Detailed tutorial on compiling and installing python3.6 on linux

1. First go to the official website https://www.p...

How React Hooks Work

Table of contents 1. React Hooks vs. Pure Functio...

Angular framework detailed explanation of view abstract definition

Preface As a front-end framework designed "f...

How to deploy hbase using docker

Standalone hbase, let’s talk about it first. Inst...

React realizes secondary linkage effect (staircase effect)

This article shares the specific code of React to...

How MySQL Select Statement is Executed

How is the MySQL Select statement executed? I rec...

The difference between HTML name id and class_PowerNode Java Academy

name Specify a name for the tag. Format <input...

Detailed tutorial on installing mysql 5.7.26 on centOS7.4

MariaDB is installed by default in CentOS, which ...

React method of displaying data in pages

Table of contents Parent component listBox List c...

Tomcat uses Log4j to output catalina.out log

Tomcat's default log uses java.util.logging, ...

How much data can be stored in a MySQL table?

Programmers must deal with MySQL a lot, and it ca...

Detailed explanation of how to copy and backup docker container data

Here we take the Jenkins container as an example ...