Knowledge

Transact-SQL

Source 📝

73: 32: 175: 433:
allow conditional execution. This batch statement will print "It is the weekend" if the current date is a weekend day, or "It is a weekday" if the current date is a weekday. (Note: This code assumes that Sunday is configured as the first day of the week in the
273:. All applications that communicate with an instance of SQL Server do so by sending Transact-SQL statements to the server, regardless of the user interface of the application. 928:
is a Transact-SQL statement that implements a bulk data-loading process, inserting multiple rows into a table, reading data from an external sequential file. Use of
660:
will wait for a given amount of time, or until a particular time of day. The statement can be used for delays or to block execution until the set time.
1176: 137: 279:
in SQL Server are executable server-side routines. The advantage of stored procedures is the ability to pass parameters.
109: 214: 156: 59: 116: 952:
logic to support exception type behaviour. This behaviour enables developers to simplify their code and leave out
786:
statements are enhanced to enable data from another table to be used in the operation, without needing a subquery:
94: 123: 90: 45: 801:. When this is done, the name or alias of which table in the join is to be deleted from is placed between 258:, various support functions for string processing, date processing, mathematics, etc. and changes to the 105: 1095: 823:
clause and referenced by alias, or referenced only at the start of the statement as per standard SQL.
531:. If more than one statement is to be controlled by the conditional in the example above, we can use 83: 1151: 251: 270: 130: 8: 1116: 937: 528: 247: 188:
Please expand the article to include this information. Further details may exist on the
189: 51: 667: 287:
Transact-SQL provides the following statements to declare and set local variables:
276: 1135: 255: 1165: 1171: 263: 259: 16:
Microsoft's and Sybase's proprietary extension to Structured Query Language
819:
clause to be added. The table to be updated can be either joined in the
19:"TSQL" redirects here. For the proposed temporal extension of SQL, see 936:
statements for each row to be added. Additional details are available
235: 72: 1105: 932:
results in better performance than processes that issue individual
684:
causes the next iteration of the loop to execute. An example of a
1110: 948:
Beginning with SQL Server 2005, Microsoft introduced additional
174: 1100: 239: 20: 773: 243: 1156: 97:. Unsourced material may be challenged and removed. 383:Keywords for flow control in Transact-SQL include 246:(Structured Query Language) used to interact with 1163: 250:. T-SQL expands on the SQL standard to include 1066:-- roll back the transaction because of error 956:checking after each SQL execution statement. 1138:, Jonathan Allen on Mar 19, 2012, infoq.com 60:Learn how and when to remove these messages 215:Learn how and when to remove this message 157:Learn how and when to remove this message 1136:"T-SQL Improvements in SQL Server 2012" 774:Changes to DELETE and UPDATE statements 613:'Get some rest on the weekend!' 1164: 666:is used to immediately return from a 168: 95:adding citations to reliable sources 66: 25: 1096:Adaptive Server Enterprise (Sybase) 643:'Get to work on a weekday!' 13: 1177:Data-centric programming languages 14: 1188: 1145: 269:Transact-SQL is central to using 41:This article has multiple issues. 242:'s proprietary extension to the 173: 71: 30: 378: 82:needs additional citations for 49:or discuss these issues on the 1129: 920: 1: 1122: 831:who have been flagged in the 793:accepts joined tables in the 943: 835:table with the 'idle' flag. 604:'It is the weekend.' 500:'It is the weekend.' 282: 7: 1089: 186:about the history of T-SQL. 10: 1193: 778:In Transact-SQL, both the 634:'It is a weekday.' 512:'It is a weekday.' 18: 1042:-- commit the transaction 979:-- execute each statement 832: 828: 827:This example deletes all 958: 837: 690: 541: 440: 301: 1152:Transact-SQL Reference 738:'Hello world.' 252:procedural programming 184:is missing information 1157:Transact-SQL Tutorial 1106:PL/pgSQL (PostgreSQL) 797:clause, similarly to 688:loop is given below. 961:-- begin transaction 271:Microsoft SQL Server 248:relational databases 91:improve this article 1117:Tabular Data Stream 676:ends the enclosing 529:block of statements 331:'Some Name' 277:Stored procedures 225: 224: 217: 207: 206: 167: 166: 159: 141: 64: 1184: 1139: 1133: 1085: 1082: 1079: 1076: 1073: 1070: 1067: 1064: 1061: 1058: 1055: 1052: 1049: 1046: 1043: 1040: 1037: 1034: 1031: 1028: 1025: 1022: 1019: 1016: 1013: 1010: 1007: 1004: 1001: 998: 995: 992: 989: 986: 983: 980: 977: 974: 971: 968: 965: 962: 955: 951: 935: 931: 927: 916: 913: 910: 907: 904: 901: 898: 895: 892: 889: 886: 883: 880: 877: 874: 871: 868: 865: 862: 859: 856: 853: 850: 847: 844: 841: 834: 830: 822: 818: 814: 808: 804: 800: 796: 792: 785: 781: 769: 766: 763: 760: 757: 754: 751: 748: 745: 742: 739: 736: 733: 730: 727: 724: 721: 718: 715: 712: 709: 706: 703: 700: 697: 694: 687: 683: 679: 675: 668:stored procedure 665: 659: 653: 650: 647: 644: 641: 638: 635: 632: 629: 626: 623: 620: 617: 614: 611: 608: 605: 602: 599: 596: 593: 590: 587: 584: 581: 578: 575: 572: 569: 566: 563: 560: 557: 554: 551: 548: 545: 538: 534: 526: 522: 516: 513: 510: 507: 504: 501: 498: 495: 492: 489: 486: 483: 480: 477: 474: 471: 468: 465: 462: 459: 456: 453: 450: 447: 444: 437: 432: 428: 422: 418: 414: 410: 406: 402: 398: 394: 390: 386: 374: 371: 368: 365: 362: 359: 356: 353: 350: 347: 344: 341: 338: 335: 332: 329: 326: 323: 320: 317: 314: 311: 308: 305: 298: 294: 290: 220: 213: 202: 199: 193: 177: 169: 162: 155: 151: 148: 142: 140: 99: 75: 67: 56: 34: 33: 26: 1192: 1191: 1187: 1186: 1185: 1183: 1182: 1181: 1162: 1161: 1148: 1143: 1142: 1134: 1130: 1125: 1101:PL/SQL (Oracle) 1092: 1087: 1086: 1083: 1080: 1077: 1074: 1071: 1068: 1065: 1062: 1059: 1056: 1053: 1050: 1047: 1044: 1041: 1038: 1035: 1032: 1029: 1026: 1023: 1020: 1017: 1014: 1011: 1008: 1005: 1002: 999: 996: 993: 990: 987: 984: 981: 978: 975: 972: 969: 966: 963: 960: 953: 949: 946: 933: 929: 925: 923: 918: 917: 914: 911: 908: 905: 902: 899: 896: 893: 890: 887: 884: 881: 878: 875: 872: 869: 866: 863: 860: 857: 854: 851: 848: 845: 842: 839: 820: 816: 812: 806: 802: 798: 794: 790: 783: 779: 776: 771: 770: 767: 764: 761: 758: 755: 752: 749: 746: 743: 740: 737: 734: 731: 728: 725: 722: 719: 716: 713: 710: 707: 704: 701: 698: 695: 692: 685: 681: 677: 673: 663: 657: 655: 654: 651: 648: 645: 642: 639: 636: 633: 630: 627: 624: 621: 618: 615: 612: 609: 606: 603: 600: 597: 594: 591: 588: 585: 582: 579: 576: 573: 570: 567: 564: 561: 558: 555: 552: 549: 546: 543: 536: 532: 524: 520: 518: 517: 514: 511: 508: 505: 502: 499: 496: 493: 490: 487: 484: 481: 478: 475: 472: 469: 466: 463: 460: 457: 454: 451: 448: 445: 442: 435: 430: 426: 420: 416: 412: 408: 404: 400: 396: 392: 388: 384: 381: 376: 375: 372: 369: 366: 363: 360: 357: 354: 351: 348: 345: 342: 339: 336: 333: 330: 327: 324: 321: 318: 315: 312: 309: 306: 303: 296: 292: 288: 285: 256:local variables 221: 210: 209: 208: 203: 197: 194: 187: 178: 163: 152: 146: 143: 100: 98: 88: 76: 35: 31: 24: 17: 12: 11: 5: 1190: 1180: 1179: 1174: 1160: 1159: 1154: 1147: 1146:External links 1144: 1141: 1140: 1127: 1126: 1124: 1121: 1120: 1119: 1114: 1113:(ISO standard) 1108: 1103: 1098: 1091: 1088: 959: 945: 942: 922: 919: 912:'idle' 838: 825: 824: 810: 775: 772: 691: 542: 441: 380: 377: 302: 284: 281: 223: 222: 205: 204: 181: 179: 172: 165: 164: 106:"Transact-SQL" 79: 77: 70: 65: 39: 38: 36: 29: 15: 9: 6: 4: 3: 2: 1189: 1178: 1175: 1173: 1170: 1169: 1167: 1158: 1155: 1153: 1150: 1149: 1137: 1132: 1128: 1118: 1115: 1112: 1109: 1107: 1104: 1102: 1099: 1097: 1094: 1093: 1036:'123' 1006:'ABC' 957: 941: 939: 836: 811: 789: 788: 787: 689: 671: 670:or function. 669: 661: 540: 530: 439: 424: 300: 280: 278: 274: 272: 267: 265: 261: 257: 253: 249: 245: 241: 237: 233: 229: 219: 216: 201: 198:November 2022 191: 185: 182:This article 180: 176: 171: 170: 161: 158: 150: 139: 136: 132: 129: 125: 122: 118: 115: 111: 108: –  107: 103: 102:Find sources: 96: 92: 86: 85: 80:This article 78: 74: 69: 68: 63: 61: 54: 53: 48: 47: 42: 37: 28: 27: 22: 1131: 947: 924: 826: 777: 680:loop, while 672: 662: 656: 519: 425: 382: 379:Flow control 286: 275: 268: 266:statements. 231: 228:Transact-SQL 227: 226: 211: 195: 183: 153: 144: 134: 127: 120: 113: 101: 89:Please help 84:verification 81: 57: 50: 44: 43:Please help 40: 930:BULK INSERT 921:BULK INSERT 539:like this: 436:@@DATEFIRST 147:August 2017 1166:Categories 1123:References 864:user_flags 833:user_flags 438:setting.) 364:CustomerID 117:newspapers 46:improve it 950:TRY CATCH 944:TRY CATCH 815:allows a 283:Variables 236:Microsoft 190:talk page 52:talk page 1090:See also 1069:ROLLBACK 682:CONTINUE 574:DATEPART 547:DATEPART 473:DATEPART 446:DATEPART 397:CONTINUE 310:NVARCHAR 1111:SQL/PSM 1018:MYTABLE 988:MYTABLE 954:@@ERROR 938:in MSDN 693:DECLARE 658:WAITFOR 586:GETDATE 559:GETDATE 527:mark a 485:GETDATE 458:GETDATE 417:WAITFOR 304:DECLARE 289:DECLARE 238:'s and 131:scholar 1045:COMMIT 1030:VALUES 1012:INSERT 1000:VALUES 982:INSERT 934:INSERT 840:DELETE 813:UPDATE 803:DELETE 799:SELECT 791:DELETE 784:UPDATE 780:DELETE 664:RETURN 419:, and 413:RETURN 337:SELECT 297:SELECT 264:UPDATE 260:DELETE 240:Sybase 133:  126:  119:  112:  104:  1081:CATCH 1063:CATCH 1060:BEGIN 973:BEGIN 964:BEGIN 897:WHERE 858:INNER 849:users 829:users 735:PRINT 732:BEGIN 720:WHILE 686:WHILE 678:WHILE 674:BREAK 640:PRINT 631:PRINT 628:BEGIN 610:PRINT 601:PRINT 598:BEGIN 533:BEGIN 521:BEGIN 509:PRINT 497:PRINT 421:WHILE 393:BREAK 385:BEGIN 361:WHERE 358:Store 352:Sales 340:@var1 325:@var1 307:@var1 234:) is 232:T-SQL 138:JSTOR 124:books 21:TSQL2 1072:TRAN 1048:TRAN 1024:NAME 1015:INTO 994:NAME 985:INTO 967:TRAN 926:BULK 906:name 861:JOIN 846:FROM 821:FROM 817:FROM 807:FROM 805:and 795:FROM 782:and 726:< 625:ELSE 535:and 523:and 506:ELSE 431:ELSE 429:and 409:ELSE 407:and 401:GOTO 387:and 349:FROM 346:Name 295:and 262:and 110:news 1172:SQL 1078:END 1057:TRY 1054:END 976:TRY 765:END 744:SET 705:SET 699:INT 649:END 619:END 589:()) 562:()) 537:END 525:END 488:()) 461:()) 389:END 370:100 322:SET 293:SET 244:SQL 93:by 1168:: 1039:); 1009:); 940:. 894:id 882:id 873:ON 867:AS 852:AS 753:@i 747:@i 723:@i 708:@i 696:@i 580:dw 571:OR 553:dw 544:IF 479:dw 470:OR 452:dw 443:IF 427:IF 423:. 415:, 411:, 405:IF 403:, 399:, 395:, 391:, 319:); 316:30 299:. 291:, 254:, 55:. 1084:; 1075:; 1051:; 1033:( 1027:) 1021:( 1003:( 997:) 991:( 970:; 915:; 909:= 903:. 900:f 891:. 888:f 885:= 879:. 876:u 870:f 855:u 843:u 809:. 768:; 762:; 759:1 756:+ 750:= 741:; 729:5 717:; 714:0 711:= 702:; 652:; 646:; 637:; 622:; 616:; 607:; 595:1 592:= 583:, 577:( 568:7 565:= 556:, 550:( 515:; 503:; 494:1 491:= 482:, 476:( 467:7 464:= 455:, 449:( 373:; 367:= 355:. 343:= 334:; 328:= 313:( 230:( 218:) 212:( 200:) 196:( 192:. 160:) 154:( 149:) 145:( 135:· 128:· 121:· 114:· 87:. 62:) 58:( 23:.

Index

TSQL2
improve it
talk page
Learn how and when to remove these messages

verification
improve this article
adding citations to reliable sources
"Transact-SQL"
news
newspapers
books
scholar
JSTOR
Learn how and when to remove this message

talk page
Learn how and when to remove this message
Microsoft
Sybase
SQL
relational databases
procedural programming
local variables
DELETE
UPDATE
Microsoft SQL Server
Stored procedures
block of statements
stored procedure

Text is available under the Creative Commons Attribution-ShareAlike License. Additional terms may apply.