当前位置:网站首页>MySQL introduction - crud Foundation (establishment of the prototype of the idea of adding, deleting, changing and searching)

MySQL introduction - crud Foundation (establishment of the prototype of the idea of adding, deleting, changing and searching)

2022-07-07 08:26:00 Ghost Knight

CRUD

create,read,update,delete

  1. Insert sentence ( Add data )
  2. Update sentence ( UPDATE statement )
  3. Delete sentence ( Delete data )
  4. Select sentence ( Find data )

Insert sentence

 Please add a picture description

Introductory cases

 Please add a picture description

details

 Please add a picture description

Update sentence

 Please add a picture description

Introductory cases

 Please add a picture description

details

  1. UPDATE Syntax to update columns in the original table row with new values .
  2. SET Clause to indicate which columns to modify and which values to give .
  3. WHERE Clause specifies which rows should be updated . If not WHERE Clause , Then update all
    That's ok ( Record ), So the teacher reminds you to be careful .
    4. If you need to modify multiple fields , Can pass set Field 1 = value 1, Field 2- value …
update employee set salary = salary + 1000,job = ' Mountain patrolling ' where name = ' Old monster '

Delete sentence

 Please add a picture description

Introductory cases

 Please add a picture description

details

  • If not used where Clause , All data in the table... Will be deleted .( Be careful )
  • Delete Statement cannot delete a - The value of the column ( You can use update Set to null perhaps ’ ')
  • Use delete Statement only delete records , Don't delete the table itself . To delete a table , Use droptable sentence .drop table Table name ;
drop table employee;

Select sentence 【 a key 】( Single table , Multiple tables )

 Please add a picture description

matters needing attention

  1. Select Specify which columns of data to query .
  2. column Specifies the column name .
  3. * Number means to query all columns .
  4. From Specify which table to query .
  5. DISTINCT Optional , When the result is displayed , Whether to remove duplicate data

Case practice

Create student table first

CREATE TABLE student (
	id INT NOT NULL DEFAULT 1,
	NAME VARCHAR ( 20 ) NOT NULL DEFAULT '',
	chinese FLOAT NOT NULL DEFAULT 0.0,
	english FLOAT NOT NULL DEFAULT 0.0,
	math FLOAT NOT NULL DEFAULT 0.0
	
);
INSERT INTO student
VALUES
	( 1, ' Taotao ', 98, 78, 90 );
INSERT INTO student
VALUES
	( 2, ' Zhang Fei ', 87, 50, 80 );
INSERT INTO student
VALUES
	( 3, ' Guan yu ', 91, 28, 30 );

 Please add a picture description

Expression column

 Please add a picture description

as sentence ( nickname )

 Please add a picture description

Case practice

 Please add a picture description

where Clause common operators

 Please add a picture description

Case practice 1

 Please add a picture description

Case practice 2

 Please add a picture description

Order by Clause

 Please add a picture description

Basic introduction

  1. Order by Specify sorted columns , The sorted column can be either the column name in the table , It can also be select The column name specified after the statement
  2. Asc Ascending [ Default ]、Desc Descending
  3. ORDER BY Clause should be in SELECT End of statement

Case presentation

 Please add a picture description

原网站

版权声明
本文为[Ghost Knight]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202130640332050.html