In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
In this issue, the editor will bring you about how to use the EXISTS structure in SQLServer. The article is rich in content and analyzes and narrates it from a professional point of view. I hope you can get something after reading this article.
How to use the EXISTS structure of SQLServer skillfully
ListingA creates a table and inserts some data so you can use the table to see how the EXISTS structure works. The script in ListingB uses the EXISTS structure to examine each row in the SalesHistory table and get a variable based on the existing row. This script will return 1 (true), which means that the SalesHistory table contains the rows you want to query.
In this case, once a record is found in the SalesHistory table, the EXISTS structure does not continue to look and returns 1 immediately. The added benefit of using the EXISTS structure is that it returns as soon as it finds a record that meets the criteria.
ListingC is similar to the script above, but its return value is 0, because under this condition, the EXISTS condition is not met.
Because of how the EXISTS structure works, the following statement implements the same function.
How to use the EXISTS structure of SQLServer skillfully
SELECT*FROMSalesHistorysh
WHEREEXISTS
(
IFEXISTS
(
SELECT*FROMSalesHistory
WHERESaleDate='1/1/2001'AND
Product='Computer'AND
SalePrice=1000
)
UPDATETOP (1) SalesHistory
SETSalePrice=1100
WHERESaleDate='1/1/2001'AND
Product='Computer'AND
SalePrice=1000
ELSE
INSERTINTOSalesHistory
(Product,SaleDate,SalePrice)
VALUES
('Computer','1/1/2001',1100)
Although you may not use the examples introduced here in the real world, they show you how to use the EXISTS structure to decide which DML type to use.
This is how the EXISTS structure in SQLServer shared by the editor is used. If you happen to have similar doubts, please refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.