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

Various problems encountered in sending emails on Alibaba Cloud Centos6.X

Preface: I have newly installed an Alibaba cloud ...

Native JS to implement paging click control

This is an interview question, which requires the...

MySQL master-slave data is inconsistent, prompt: Slave_SQL_Running: No solution

This article uses an example to describe the solu...

How to use echarts to visualize components in Vue

echarts component official website address: https...

Browser compatibility summary of common CSS properties (recommended)

Why do we need to summarize the browser compatibi...

How to generate mysql primary key id (self-increment, unique and irregular)

Table of contents 1. Use the uuid function to gen...

js dynamically adds example code for a list of circled numbers

1. Add the ul tag in the body first <!-- Unord...

HTML table markup tutorial (9): cell spacing attribute CELLSPACING

A certain distance can be set between cells in a ...

How to set up cross-domain access in IIS web.config

Requirement: The page needs to display an image, ...

How to manually upgrade the kernel in deepin linux

deepin and Ubuntu are both distributions based on...

Detailed explanation of process management in Linux system

Table of contents 1. The concept of process and t...

Linux firewall iptables detailed introduction, configuration method and case

1.1 Introduction to iptables firewall Netfilter/I...

Implementation example of react project from new creation to deployment

Start a new project This article mainly records t...