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

React handwriting tab switching problem

Parent File import React, { useState } from '...

JavaScript canvas to achieve colorful clock effect

Use canvas to write a colorful clock! 1. Title (1...

Analyze the difference between computed and watch in Vue

Table of contents 1. Introduction to computed 1.1...

Solution to css3 transform transition jitter problem

transform: scale(); Scaling will cause jitter in ...

Learn MySQL execution plan

Table of contents 1. Introduction to the Implemen...

MySQL startup error InnoDB: Unable to lock/ibdata1 error

An error message appears when MySQL is started in...

Disable input text box input implementation properties

Today I want to summarize several very useful HTML...

Examples of using temporary tables in MySQL

I've been a little busy these two days, and t...

Introduction to fuzzy query method using instr in mysql

Using the internal function instr in MySQL can re...

Sharing tips on using scroll bars in HTML

Today, when we were learning about the Niu Nan new...

How to configure Nginx virtual host in CentOS 7.3

Experimental environment A minimally installed Ce...

How to package the project into docker through idea

Many friends have always wanted to know how to ru...