mysql statement realizes simple operation examples of adding deleting modifying and checking
- 2021-12-04 20:02:01
- OfStack
This paper describes the simple operation of adding, deleting, modifying and checking mysql statement. Share it for your reference, as follows:
1. Create an db_shop database, or if the database does not exist
create database if not exists db_shop;
2. Delete the database, if the data exists, delete it
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 from the old table
create table tb_goods01 like tb_goods;
5. Delete the data table
drop table tb_goods01;
6. Add 1 column (1 field) to 1 table
alter tb_goods add column goodsName varchar(255) after goodsId;
Note: If after is not written, before is added to the last 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. Inquiry
Query all
select * from tb_goods;
Query specific
select goodsName fromtb_goods;
Fuzzy search
drop database if exists db_shop;
0
10. Update the data table
drop database if exists db_shop;
1
More readers interested in MySQL can check out the topics on this site: "MySQL Query Skills Encyclopedia", "MySQL Common Function Summary", "MySQL Log Operation Skills Encyclopedia", "MySQL Transaction Operation Skills Summary", "MySQL Stored Procedure Skills Encyclopedia" and "MySQL Database Lock Related Skills Summary"
I hope this article is helpful to everyone's MySQL database.