当前位置:网站首页>Nodejs database (Part 2)

Nodejs database (Part 2)

2022-06-11 07:00:00 Yu Mei

1.SQL Of select sentence

1.1 Grammar introduction

  1. SELECT Statement is used to query data from a table , The results of the execution are stored in a result table ( Called result set )
     Insert picture description here
  2. Be careful :SQL Keywords in statements are case insensitive
  3. When executing a statement , You need to select the default database , Double click to select the specified database

1.2 Demonstrate two SELECT sentence

  1. Query all column writing methods
    from users Select all the columns in the table , You can use symbols * Replace the name of the column
     Insert picture description here

  2. SELECT Column name
    Get the name username and password The contents of the column ( From the name users Database table of ) Insert picture description here

2.SQL Of insert into sentence

  1. grammar : Used to insert new data rows into the data table
     Insert picture description here

  2. Be careful : New data needs to be quoted , Otherwise, an error will be reported

3.SQL Of update sentence

  1. grammar :Update Statement is used to modify the data in the table
     Insert picture description here

  2. Between multiple updated Columns , Use English commas to separate

  3. where Followed by the updated conditions

  4. Be careful : Beginners often forget to provide updated where Conditions , This will cause the data of the whole table to be updated , Be careful

4.SQL Of delete sentence

  1. grammar :DELETE Statement to delete rows in a table
     Insert picture description here

5.where Clause

  1. WHERE Clause is used to limit the selection criteria . stay SELECT、UPDATE、DELETE In the sentence , Can be used WHERE Clause to limit the selection criteria

 Insert picture description here
2. Can be found in WHERE Operators used in Clauses

 Insert picture description here

  1. Can pass WHERE Clause to qualify SELECT Query criteria for
--  Inquire about  id  by  1  All users of 
select * from users where id=1

--  Inquire about  id  Greater than  2  All users of 
select * from users where id>2

-- Inquire about  username  It's not equal to  admin  All users of 
select * from users where username<>'admin'

6.SQL Of AND and OR Operator

  1. AND and OR Can be found in WHERE The combination of two or more conditions in a sub statement
  2. AND Indicates that multiple conditions must be met at the same time , amount to JavaScript Medium && Operator , for example if (a !== 10 && a !== 20)
  3. OR It means that as long as any condition is satisfied , amount to JavaScript Medium || Operator , for example if(a !== 10 || a !== 20)
  4. Case code
-- and
--  Use  AND  To display all  status  by  0, also  id  Less than  3  Users of 

select * from users where status=0 and id<3
-- or
--  Use  OR  To display all  status  by  1, perhaps  username  by  zs  Users of 

select * from users where status=0 or username='zs'

7.SQL Of order by Clause

  1. grammar
  • ORDER BY Statement to sort the result set according to the specified column
  • ORDER BY By default, statements sort records in ascending order ,ASC Keywords represent ascending sorting
  • If you want to sort records in descending order , have access to DESC keyword
  1. ORDER BY Clause - Ascending sort
    Yes users Table data , according to status Fields are sorted in ascending order
--  The following two  SQL  Statements are equivalent ,
--  because  order by  Sort in ascending order by default 
--  among ,ASC  Keywords represent ascending sorting 

-- select * from users order by status
select * from users order by status asc
  1. ORDER BY Clause – null
    Yes users Table data , according to id Fields are sorted in descending order
-- desc  Represents a descending sort 

select * from users order by status desc

8.ORDER BY Clause – Multiple sort

  1. Yes users Table data , First according to status Fields are sorted in descending order , Again according to username In alphabetical order , Sort in ascending order
  2. Case code
select * from users order by status desc, username asc

9.id Uniqueness

  1. After inserting data , Find data id There is an interval
  2. There was before , It was later deleted , So after adding data , Even if this id Have been deleted , This id Will not be occupied
原网站

版权声明
本文为[Yu Mei]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/03/202203020524234969.html