当前位置:网站首页>Addition, deletion, modification and query of mysql~ tables (detailed and easy to understand)
Addition, deletion, modification and query of mysql~ tables (detailed and easy to understand)
2022-06-25 18:26:00 【Zebra and running】
Catalog
(1). Single line data + Insert all columns
(2). Multi row data + Specify column insertion
(3). The query field is an expression
(5). duplicate removal :DISTINCT
(7). ( important ) Conditions of the query :WHERE
4).NULL Query for :IS [NOT] NULL
(9). Paging query :LIMIT(MySQL special )
eg: Use paging query to select the students with the second Chinese score
6. The main content is summary
(1). How to delete Id Maximum value
1.CRUD
- notes : stay SQL Can be used in “-- Space + describe ” To indicate a comment
- CRUD That is, increase (Create)、 Inquire about (Retrieve)、 to update (Update)、 Delete (Delete) An acronym for four words .
2. newly added (Create)
grammar :
give an example :
(1). Single line data + Insert all columns
(2). Multi row data + Specify column insertion
1. The string in the database is a single quotation mark
2. Generally, the database should have a unique field to identify the table , stay java In order to correspond to the database , That also needs to have such an attribute
3. Write later , Try to use only the writing method of the specified column insertion , Because if you don't specify column insertion , In the future, if you add a field to your table , Then the previous statement will report an error
4. Annotation syntax :-- Space
3. Inquire about (Retrieve)
grammar :
(1). Full column query
(2). Specified column query
(3). The query field is an expression
When the query field is an expression , He'll check later , Calculate by yourself and then output
(4). Alias
Specify aliases for columns in query results , Represents the returned result set , Use alias as the name of the column .
grammar :
- Tips: Alias “ Total score ” I can add as
- notes : Here you can see , The data we show here is the result set returned to us by the database . The black box here is the client , The database is the server
(5). duplicate removal :DISTINCT
Use DISTINCT Keyword to de duplicate a column of data :
distinct Put in front of the field to be specified , And only one field can be added
(6). Sort :ORDER BY
Java Sort :(1) Algorithmic sorting (2)java Compare interfaces for sorting
grammar :
1. No, ORDER BY Clause , The order of return is undefined , Never rely on this order
2. NULL Data sorting , Treat as less than any value , The ascending order appears at the top , Descending order appears at the bottom
3. Use expressions and aliases to sort
4. You can sort multiple fields , The order of priority follows the order of writing
5.order by In general, and limit Use it together , Used to select the first three elements .
(7). ( important ) Conditions of the query :WHERE
Comparison operator :
The comparison operators and java The comparison operators inside are different
- = It's a comparison operator , Means to judge equal , No more java Inside == 了
- As long as you know = Can , It doesn't mean just knowing != Just go
Logical operators :
1). The basic query
- Be careful WHERE Conditions can be expressed as , But you can't use aliases .
2). Range queries
--BETWEEN ... AND ...
--IN
3). Fuzzy query :LIKE
- % The match is 0 Characters or more , For example, there is only one ‘ Grandchildren ’, That's only ‘ Grandchildren %’ Can match
- _ The match is a character
4).NULL Query for :IS [NOT] NULL
(8). Use and query of dates
1. Create a table with dates
- Here we need to set a default value for the date , But I don't have to set the default value myself .
- Set the default value to null That's all right.
2.mysql Default date format :yyyy-MM-dd HH:mm:ss
Insert data with date
3. Query date field
Like other fields , You can also query between-and.
4.
(9). Paging query :LIMIT(MySQL special )
grammar :
- s It's the offset ( Just offset a few first ),n Indicates the number of filter results
- the second LIMIT s,n Means screening n Bar result , From s Data starts
- Third LIMIT n OFFSET s Means screening n Bar result , From s Data starts
- This is not to suggest a third , The second kind can also , It depends on which one you use more smoothly , One is to s after n, The other is to n after s, I suggest the third , Because no s The time is LIMIT n
- Order by In general, and limit Use it together
eg: Use paging query to select the students with the second Chinese score
select * from exam_result order by chinese desc limit 1 offset 1
4. modify (Update)
grammar :
- stay set When , If the length of the value exceeds the length given when creating the table , Will report a mistake .
- Like the last set chinese = chinese * 2; You may report an error
- If not where,order by And so on , That is, the values of the whole column of elements are modified
5. Delete (Delete)
grammar :
Be careful delete from table_name, There's nothing in the back , That is, the whole table is deleted , Be sure to pay attention to . To add where,order by,limit etc.
6. The main content is summary
(1). How to delete Id Maximum value
mysql in You can't specify target table for update in FROM clause The wrong meaning is to say , Not first select Give some values in the same table , Again update This table ( In the same sentence ).
error :
correct :
(2). Normal summary
newly added :
Inquire about :
modify :
Delete :
边栏推荐
- Redis command string
- [deeply understand tcapulusdb technology] tmonitor system upgrade
- General message publishing and subscription in observer mode
- anaconda下载清华源
- 1. Understanding of norm
- [deeply understand tcapulusdb technology] create a game area for document acceptance
- 【深入理解TcaplusDB技术】单据受理之创建游戏区
- [in depth understanding of tcapulusdb technology] tcapulusdb operation and maintenance doc
- Slam visuel Leçon 14 leçon 9 filtre Kalman
- Dell r530 built in hot spare status change description
猜你喜欢
[in depth understanding of tcapulusdb technology] tcapulusdb operation and maintenance
Part 5:vs2017 build qt5.9.9 development environment
[in depth understanding of tcapulusdb technology] how to realize single machine installation of tmonitor
Leetcode force buckle (Sword finger offer 26-30) 26 Substructure of tree 27 Image of binary tree 28 Symmetric binary tree 29 Print matrix 30 clockwise Stack containing min function
Uncover ges super large scale graph computing engine hyg: Graph Segmentation
SQL Server实时备份库要求
How can the self-supporting number evaluation be safer for cross-border e-commerce platforms such as Amazon, eBay, shopee, lazada, express, Wal Mart and Alibaba international?
【深入理解TcaplusDB技术】如何实现Tmonitor单机安装
Hash of redis command
[in depth understanding of tcapulusdb technology] tcapulusdb model
随机推荐
【深入理解TcaplusDB技术】单据受理之事务执行
Is it safe for a securities company to open an account with the lowest handling fee among the top ten
[deeply understand tcapulusdb technology] tcapulusdb import data
One article solves all search backtracking problems of Jianzhi offer
[compréhension approfondie de la technologie tcaplusdb] sauvegarde des données d'affaires tcaplusdb
connect to address IP: No route to host
RMAN备份数据库_目录
RMAN备份数据库_跳过脱机,只读和不可访问的文件
QT generate random numbers (random strings) within the specified range
【深入理解TcaplusDB技术】 Tmonitor模块架构
【深入理解TcaplusDB技术】集群管理操作
【深入理解TcaplusDB技术】TcaplusDB业务数据备份
New typereference usage fastjson[easy to understand]
Introduction to microservices
Which is better and safer, GF easy gold rush or compass
[deeply understand tcapulusdb technology] tmonitor system upgrade
[in depth understanding of tcapulusdb technology] tcapulusdb operation and maintenance
Iet attends the 2022 World Science and technology community development and Governance Forum and offers suggestions for building an international science and technology community
RMAN backup database_ Skip offline, read-only, and inaccessible files
[how do I refresh the shuttle page after jumping back?]