SQL Server Update: Use TOP to limit updated data

Source: Internet
Author: User

The original text uses TOP to limit updated data

You can use the TOP clause to limit the number of rows modified in the UPDATE statement. When the TOP (N) clause is used with UPDATE, the delete operation is performed on the randomly selected n rows. For example, suppose you want to reduce the sales burden for a senior salesperson and assign some customers to a junior sales person. The following example assigns a randomly sampled 10 customers from one salesperson to another.

Transact-SQL:
TOP (Ten) Sales.storeset SalesPersonID = 276WHERE SalesPersonID = 275; GO

If you need to use top to apply updates arranged in a meaningful chronological order, you must use both the top and order BY clauses. The following example updates the number of vacation hours for the first 10 employees hired.

Transact-SQL
HumanResources (SELECT TOP BusinessEntityID from HumanResources.Employee     ORDER by HireDate ASC)th  HumanResources.Employee. BusinessEntityID = th. BusinessEntityID; GO
Gmt
Detection languageWorld languageChinese SimplifiedChinese TraditionalDanishUkrainianUzbek languageUrdu languageArmenianIgbo languageRussianBulgarianSinhala languageCroatianIcelandicGalicianCatalanHungarianZulu, South AfricaKannada languageHindiIndonesian SundaIndonesian JavaneseIndonesian languageGujaratiKazakhTurkishTajik languageSerbian languageSesotho languageWelshBengaliCebu languageNepalese languageBasque languageBoolean language (Afrikaans)HebrewGreekGermanItalianYiddishLatin languageLatvianNorwegianCzechSlovakSlovenianSwahiliPunjabiJapaneseGeorgian languageMaoriFrenchPolishBosnianPersianTeluguTamilThaiHaitian CreoleIrishEstonianSwedishBelarusian languageLithuanianSomalia languageYorubaBurmese languageRomanian languageLao languageFinnishHmongEnglishDutchFilipinoPortugueseMongolianSpanishHausa languageVietnameseAzerbaijani languageAlbanianArabicKoreanFYRO MacedonianMalagasy languageMarathiMalayalamMalayMalteseKhmer languageChichewa language World languageChinese SimplifiedChinese TraditionalDanishUkrainianUzbek languageUrdu languageArmenianIgbo languageRussianBulgarianSinhala languageCroatianIcelandicGalicianCatalanHungarianZulu, South AfricaKannada languageHindiIndonesian SundaIndonesian JavaneseIndonesian languageGujaratiKazakhTurkishTajik languageSerbian languageSesotho languageWelshBengaliCebu languageNepalese languageBasque languageBoolean language (Afrikaans)HebrewGreekGermanItalianYiddishLatin languageLatvianNorwegianCzechSlovakSlovenianSwahiliPunjabiJapaneseGeorgian languageMaoriFrenchPolishBosnianPersianTeluguTamilThaiHaitian CreoleIrishEstonianSwedishBelarusian languageLithuanianSomalia languageYorubaBurmese languageRomanian languageLao languageFinnishHmongEnglishDutchFilipinoPortugueseMongolianSpanishHausa languageVietnameseAzerbaijani languageAlbanianArabicKoreanFYRO MacedonianMalagasy languageMarathiMalayalamMalayMalteseKhmer languageChichewa language
Text-to-speech feature is limited to 200 characters
Options: History: Feedback: Donate Shut down

SQL Server Update: Use TOP to limit updated data

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.