当前位置:网站首页>SQL database syntax learning notes
SQL database syntax learning notes
2022-04-23 18:15:00 【Talent、me】
Recently I came across a project , Need to use SQL Access data in the database area , I found that I can only use some basic instructions and can't freely operate the results I want in the project , then , I went online again and sorted out the instruction set syntax of the database .
1. The most basic addition, deletion, modification and query instructions
| Instructions | effect |
|---|---|
| insert | insert data |
| delete | Delete data |
| select | Find data |
| update | modify / Update data |
Basically, most database operations are composed according to the above four instructions .
2.Select Search instructions
select I personally think instruction is the most important , So first analyze this point .
| Operation action | Instructions |
|---|---|
| Traverse all the values | select *( All columns ) from tablename( The name of the table ) |
| Specifies to traverse a column or columns | select colunm_name( Name ) from tablename |
| Through conditions (where) To filter the data that meets the conditions | select *( All columns ) from tablename where colunm_name = ‘xxxx’( Text ) perhaps select *( All columns ) from tablename where colunm_name = xxxx( Integers ) |
| Multiple conditions (and perhaps or) To filter data | select *( All columns ) from tablename where (colunm_name = ‘xxx’ or colunm1_name = ’ xxx’)and colunm_name=‘xxxx’ |
| Through wildcards (Like) Maladjustment (%,_,[]) | select *( All columns ) from tablename where colunm_name=’%xx’ |
| Arrange the data table order by( Ascending ) perhaps order by xxx desc( Descending ) | select * from tablename order by Name / order by Name desc |
| Get different options in the column | select distinct colunm_name from tablename |
| Specify that a column satisfies multiple values (in) | select *( All columns ) from tablename where colunm_name in(value1,value2,value3,…) |
| Insert data from one table into another | select *( All columns ) into newtablename from oldtable (where xxx) |
| Retrieve two tables at the same time ( Usually the primary key primary key And foreign keys ) | select *tableonename.xxx( Name ),tabletwoname.xxx from tableonename( Table name ),tabletwoname where tableoneonename.number = tabletwoname.number |
The above table is just a template for instructions , But many times, we need to pass some examples to make some examples understand , To draw inferences from one instance , So next, I will demonstrate the above template through some simple examples .
First create a table
create table if not exists studenttable( ID integer primary key,Name vchar(20) not null,Class vchar(10) not null,Score int)"
//primary key Primary key
//autoincrement Auto increment
//not null Can't be empty
1. Print out everything in the table
select * from studenttable
| Student number | full name | class | achievement |
|---|---|---|---|
| 164001 | Xiao Ming | 3 class | 80 |
| 164002 | Hill | 2 class | 60 |
| 164003 | Little ni | 2 class | 73 |
| 164004 | Small | 4 class | 40 |
2. Just print out the student number and name
select ID,Name from studenttable
| Student number | full name |
|---|---|
| 164001 | Xiao Ming |
| 164002 | Hill |
| 164003 | Little ni |
| 164004 | Small |
3. Satisfying the class is 2 Class
select * from studenttable where Class = '2 class '
| Student number | full name | class | achievement |
|---|---|---|---|
| 164002 | Hill | 2 class | 60 |
| 164003 | Little ni | 2 class | 73 |
4. Satisfying the class is 2 The grade of the class at the same time is greater than 60
select * from studenttable where Class = '2 class ' and Score > 60
| Student number | full name | class | achievement |
|---|---|---|---|
| 164003 | Little ni | 2 class | 73 |
5. Filter names with ‘ Ni ’ Students of Chinese characters
select * from studenttable where Name=’% Ni ’
| Student number | full name | class | achievement |
|---|---|---|---|
| 164003 | Little ni | 2 class | 73 |
6. Satisfying the class is 3 Class or 4 My classmates
select * from studenttable where Class in('3 class ','4 class ')
| Student number | full name | class | achievement |
|---|---|---|---|
| 164003 | Little ni | 2 class | 73 |
| 164004 | Small | 4 class | 40 |
7. By specifying the student number in one table to retrieve the information in another table ( important )
First create another table
create table if not exists awardstable( ID integer,Awards vchar(10) not null)"
| Student number | prize |
|---|---|
| 164003 | The first prize |
| 164006 | The second prize |
| 164008 | The third prize |
| 164002 | The third prize |
select studenttable.Name,awardstable.Awards from studenttable,awardstable where studenttable.ID = awardstable.ID
| Student number | prize |
|---|---|
| Little ni | The first prize |
| Hill | The third prize |
8、 Get how many classes there are through classes
select distinct Class from studenttable
| class |
|---|
| 2 class |
| 3 class |
| 4 class |
delete Delete instruction
| Operation action | Instructions |
|---|---|
| Delete all data | delete from tablename( Table name ) /delete * from tablename |
| Delete a column in the table equal to a specific value | delete from tablename( Table name ) where colunms_name = ‘xxxx’ |
Follow the example of the student form above
1. Empty the student list ( Just clear the data , Data and structures still exist )
delete from studenttable
2. Delete... From the table 2 My classmates
delete from studenttable where Class = '2 class '
| Student number | full name | class | achievement |
|---|---|---|---|
| 164003 | Little ni | 2 class | 73 |
| 164004 | Small | 4 class | 40 |
To be continued ......
版权声明
本文为[Talent、me]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204210610471723.html
边栏推荐
- Rust: how to implement a thread pool?
- The vivado project corresponding to the board is generated by TCL script
- Implement a simple function to calculate the sum of all integers between M ~ n (m < n)
- I / O multiplexing and its related details
- Spark performance optimization guide
- JD freefuck Jingdong HaoMao control panel background Command Execution Vulnerability
- MATLAB小技巧(6)七种滤波方法比较
- Generate verification code
- Secure credit
- word frequency count
猜你喜欢

由tcl脚本生成板子对应的vivado工程

Gobang game based on pyGame Library

Install the yapiupload plug-in in idea and upload the API interface to the Yapi document

Visualization of residential house prices

idea中安装YapiUpload 插件将api接口上传到yapi文档上

【ACM】376. Swing sequence

powerdesigner各种字体设置;preview字体设置;sql字体设置

Robocode tutorial 5 - enemy class

Data stream encryption and decryption of C

Hard core parsing promise object (do you know these seven common APIs and seven key questions?)
随机推荐
Svn simple operation command
Selenium + webdriver + chrome realize Baidu to search for pictures
Docker 安装 MySQL
[UDS unified diagnostic service] (Supplement) v. detailed explanation of ECU bootloader development points (1)
re正則錶達式
Install the yapiupload plug-in in idea and upload the API interface to the Yapi document
Jenkspy package installation
C language to achieve 2048 small game direction merging logic
Robocode tutorial 7 - Radar locking
Box pointer of rust
由tcl脚本生成板子对应的vivado工程
Identification verification code
PowerDesigner various font settings; Preview font setting; SQL font settings
Docker 安装 Redis
Rust: shared variable in thread pool
JD freefuck Jingdong HaoMao control panel background Command Execution Vulnerability
Win1远程出现“这可能是由于credssp加密oracle修正”解决办法
Pointers in rust: box, RC, cell, refcell
Nodejs安装
【ACM】70. 爬楼梯