当前位置:网站首页>MySQL add / delete / modify query SQL statement exercise yyds dry goods inventory
MySQL add / delete / modify query SQL statement exercise yyds dry goods inventory
2022-06-29 06:03:00 【wangzx_ mm】
Some operations on the database :
Get into mysql Command line : mysql -uroot –p
View all databases : show databases;
Create database : create database wg charset utf8;
Delete database : drop database wg;
Select database : use databases;
View all tables : show tables;
Look at the statement to create the database :show create database databasename;
Look at the statement that created the table :show create table tablename;
View table structure :desc tablename;
increase :
mysql> use wg;
mysql> create table students( id int auto_increment primary key,name varchar(10) not null,sex varchar(12),address varchar(50),phone int not null unique);
# Self growth auto_increment
# Non empty not null
# The default value is default ‘xx’
# only unique
# Specify character set charset
# Primary key primary key
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
mysql> create table scores(id int auto_increment primary key,s_id int not null,grade float not null);
data :
mysql> insert into students (id,name,sex,phone) values(122,’wg’,’ male ’,’110’);
mysql> insert into students values(111,’wg’,’121’,’dd’) ;
Delete :
mysql> drop table tablename;
mysql> truncate tablename; Quickly delete table data , Self growth id From the beginning , Fast , Delete directly from disk , Irrecoverable
mysql> delete from student; Delete the data of the whole table , Self growth continues
Truncate Table name
Change :
mysql> alter table oldtable( Original table name ) rename newtable( Later table names ); Change the name of the watch
Modify table data
mysql> alter table scores( Name of table ) modify s_id( The data table ) varchar(20)( The type of watch );


mysql> alter table scores( Name of table ) change s_id( The original name of the data ) scoresss ( The name of the data modification )varchar(16)( Type of data ); Modify table structure

mysql> alter table scores( Name of table ) add age( Added name ) float( Added type )after id( Behind whom ); Location of new fields (age On the ID Back )

mysql> update student set age=18 where name=‘hh’; Just modify it

check :
mysql> show create table tablename; View the new table statement
mysql> desc tablename; View table structure
mysql> show tables; View all tables
mysql> select * from students limit 5; Inquire about 5 strip
mysql> select * from students limit 1,5; Start with the number , Below n strip
mysql> SELECT * from students where sex=‘ male ’; # Specified conditions
mysql> SELECT * from students where sex=‘ male ’ and age>10; # Multiple conditions , Must satisfy at the same time
mysql> SELECT * from students where sex=‘ male ’ or sex=‘ Unknown ’ ; # Multiple conditions , One satisfaction is enough
mysql> SELECT * from students where sex !=‘ male ’; #<> It doesn't mean
mysql> SELECT * FROM students where addr like ‘% Tokyo %’;# Fuzzy matching ,% Represents a wildcard , Must use like
mysql> SELECT * from students a where a.stu_name like ‘ a surname _’;#_ Wildcards denote any single character , The word Yao can only be followed by one word
mysql> SELECT a.stu_name ‘ Student name ’,a.phone ‘ Student phone ’ from students as a where a.stu_name=‘ Yao yuan ’;# Alias a table ,as It can be omitted
SELECT * from students a where a.money BETWEEN 1000 and 10000;# Data between what
SELECT * from students ORDER BY money desc; #order by xxx desc, According to which field to continue sorting , The default is ascending , The descending order is desc, Ascending asc
SELECT * from students a where a.addr = ‘’ or a.addr is null; # Query data with empty field
SELECT DISTINCT a.money from students a ;# duplicate removal
SELECT COUNT(*) ‘ Number of students ’ from students where sex=‘ Woman ’; # The statistical number of rows
SELECT MAX(a.money) Most money from students a; # Maximum
SELECT min(money) Least money from students;# minimum value
SELECT AVG(a.money) How much is it on average from students a; # The average
SELECT sum(a.money) What's the total cost? from students a;# The sum of the
Backup database :
mysqldump -uroot -p123456 db > db.sql
mysqldump -uroot -p123456 -A > all.sql
Restore data :
mysql -uroot -p123456 db < db.sql


边栏推荐
- 5- (4-benzoimide phenyl) - 10,15,20-triphenylporphyrin (battph2) and its Zn complex (battpzn) / tetra (4-aminophenyl) porphyrin (tapph2) Qiyue supply
- Boost the digital economy and face the future office | the launch of the new version of spreadjsv15.0 is about to begin
- Is it safe to open a securities account? Is there any danger
- Leetcode theme [array] -217- there are duplicate elements
- Awk of shell script
- Loosely matched jest A value in tohavebeencalledwith - loose match one value in jest toHaveBeenCalledWith
- Internet enterprises need CRM software to help
- Multiline regular expression search in Visual Studio code - multiline regular expression search in Visual Studio code
- JS messagechannel transport
- D Author: import C programming in D
猜你喜欢

Openfpga wishes you a happy Lantern Festival!

Research Report on the recommended lithography industry in 2022 industry development prospect market investment analysis (the attachment is a link to the network disk, and the report is continuously u

Tcapulusdb Jun · industry news collection (III)

2022 recommended REITs Industry Research Report investment strategy industry development prospect market analysis (the attachment is a link to the online disk, and the report is continuously updated)

ICLR is going to have a big discussion on the deep generation model. Max welling and the winner of the AAAI million dollar award are here. Bengio is one of the organizers

2022 recommended quantum industry research industry development planning prospect investment market analysis report (the attachment is a link to the online disk, and the report is continuously updated

Analysis report on the investment market situation of the development planning prospect of the recommended chip industry research industry in 2022 (the attachment is a link to the network disk, and th

HTTP Caching Protocol practice

Leetcode simple question: judging the color of a grid on a chess board

Regular expressions for shell script values
随机推荐
2022 recommended trend toy blind box industry research report industry development prospect market analysis white paper (the attachment is a link to the network disk, and the report is continuously up
Week 10 - task 3- from point to circle to cylinder
Jenkins operation Chapter 5 trigger, configuration webhook, Jenkins parameterized construction
Analysis of ArrayList set in teacher Yang's class
Hustoj SPJ example
Rich material libraries make modeling easy and efficient for developers
Tcapulusdb Jun · industry news collection (III)
Internet enterprises need CRM software to help
证券开户安全么,有没有什么危险呢
Research Report on the new energy industry of recommended power equipment in 2022 industry development prospect market investment analysis (the attachment is a link to the network disk, and the report
2022 recommended precious metal industry research report industry development prospect market analysis white paper (the attachment is a link to the online disk, and the report is continuously updated)
3 frequently tested SQL data analysis questions (including data and code)
證券開戶安全麼,有沒有什麼危險呢
Spark saving to external data source
Manual (functional) test 1
嵌入式RTOS
Analysis report on the investment market situation of the development planning prospect of the recommended chip industry research industry in 2022 (the attachment is a link to the network disk, and th
Quickly write MVVM code using source generators
ASP. Net core 6 framework unveiling example demonstration [03]:dapr initial experience
The translation of those exquisite lines in the eighth season of the big bang