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

Several ways to submit HTML forms_PowerNode Java Academy

Method 1: Submit via the submit button <!DOCTY...

Docker image import and export code examples

Import and export of Docker images This article i...

JavaScript implements simple calculator function

This article example shares the specific code of ...

JS deep and shallow copy details

Table of contents 1. What does shallow copy mean?...

How to clean up Alibaba Cloud MySQL space

Today I received a disk warning notification from...

Two ways to visualize ClickHouse data using Apache Superset

Apache Superset is a powerful BI tool that provid...

How to select all child elements and add styles to them in CSS

method: Take less in the actual project as an exa...

MySQL 8.0.20 Installation Tutorial with Pictures and Text (Windows 64-bit)

1: Download from mysql official website https://d...

A brief understanding of the relevant locks in MySQL

This article is mainly to take you to quickly und...

Docker installation and configuration image acceleration implementation

Table of contents Docker version Install Docker E...