Examples of simple add, delete, modify, and query operations using mysql statements

Examples of simple add, delete, modify, and query operations using mysql statements

This article uses examples to describe how to use MySQL statements to implement simple add, delete, modify, and query operations. Share with you for your reference, the details are as follows:

1. Create the db_shop database. If the database does not exist, create it

create database if not exists db_shop;

2. Delete the database if the data exists

drop database if exists db_shop;

3. Create a data table for db_shop

use db_shop;
drop table if exists tb_goods;
CREATE TABLE tb_goods(
 `goodsId` int(11) NOT NULL AUTO_INCREMENT,
 PRIMARY KEY (`tb_goods`)
);

4. Create a new table based on the old table

create table tb_goods01 like tb_goods;

5. Delete the data table

drop table tb_goods01;

6. Add a column (a field) to a table

alter tb_goods add column goodsName varchar(255) after goodsId;

Note: If you don't write after or before, it will be added to the end by default

7. Delete fields

alter table tb_goods drop column goodsName;

8. Insert data

insert into tb_goods (goodsId,goodsName) values ​​(1002,'Commodity 1');

9. Query

Search all

select * from tb_goods;

Query Specific

select goodsName from tb_goods;

Fuzzy search

select * from tb_goods like '% Commodity%';

10. Update the data table

update tb_goods set goodsName='Commodity 2';

Readers who are interested in more MySQL-related content can check out the following topics on this site: "MySQL query skills", "MySQL common functions summary", "MySQL log operation skills", "MySQL transaction operation skills summary", "MySQL stored procedure skills" and "MySQL database lock related skills summary"

I hope this article will be helpful to everyone's MySQL database design.

You may also be interested in:
  • PHP+MYSQL implements user addition, deletion, modification and query
  • Summary of basic addition, deletion, query and modification operations on indexes in MySQL
  • mysql add, delete, modify and query basic statements
  • Simple implementation of Mysql add, delete, modify and query statements
  • An example of nodejs operating mysql to achieve addition, deletion, modification and query
  • Summary of examples of MySQL add, delete, query and modify statements
  • Self-written class for adding, deleting, modifying and querying MySQL database using PDO
  • Summary of Mysql table, column, database addition, deletion, modification and query problems
  • PHP implements the object-oriented mysqli extension library to add, delete, modify and query operation tool class
  • Using PHP to access the MySql database logical operations and examples of adding, deleting, modifying and checking
  • MySQL statement arrangement and summary introduction

<<:  SSM projects are frequently deployed as war packages, using tomcat and maven to implement hot deployment configuration

>>:  Implementation of webpack code fragmentation

Recommend

How to use resize to implement image switching preview function

Key Points The CSS resize property allows you to ...

MySQL query statement simple operation example

This article uses examples to illustrate the simp...

MySQL database must know sql statements (enhanced version)

This is an enhanced version. The questions and SQ...

Nginx reverse proxy configuration removes prefix

When using nginx as a reverse proxy, you can simp...

CentOS7 deploys version 19 of docker (simple, you can follow it)

1. Install dependency packages [root@localhost ~]...

How to use physics engine joints in CocosCreator

Table of contents mousejoint mouse joint distance...

Detailed explanation of nginx installation, deployment and usage on Linux

Table of contents 1. Download 2. Deployment 3. Ng...

The background color or image inside the div container grows as it grows

Copy code The code is as follows: height:auto !im...

JavaScript canvas to achieve mirror image effect

This article shares the specific code for JavaScr...

MySQL 8.0.21 free installation version configuration method graphic tutorial

Six steps to install MySQL (only the installation...

Install and configure MySQL under Linux

System: Ubuntu 16.04LTS 1\Download mysql-5.7.18-l...

How to recover files accidentally deleted by rm in Linux environment

Table of contents Preface Is there any hope after...

Example method to view the IP address connected to MySQL

Specific method: First open the command prompt; T...