This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DECLARE cursor_name [ INSENSITIVE ] [ SCROLL ] CURSOR | |
FOR select_statement | |
[ FOR { READ ONLY | UPDATE [ OF column_name [ ,...n ] ] } ] | |
[;] | |
Transact-SQL Extended Syntax | |
DECLARE cursor_name CURSOR [ LOCAL | GLOBAL ] | |
[ FORWARD_ONLY | SCROLL ] | |
[ STATIC | KEYSET | DYNAMIC | FAST_FORWARD ] | |
[ READ_ONLY | SCROLL_LOCKS | OPTIMISTIC ] | |
[ TYPE_WARNING ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE NONCLUSTERED INDEX IDX_Orders ON [ORDER](OrderDate); | |
GO | |
SELECT * | |
FROM [ORDER] ord | |
WITH (INDEX(IDX_Orders)) | |
WHERE ord.OrderDate BETWEEN '20120828' AND '20120830'; | |
GO | |
/** Output **/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE INDEX "index_name" ON "table_name" (column_name); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DECLARE @myDecimalValue FLOAT | |
SET @myDecimalValue = 4521312.531 | |
SELECT CONVERT(INT, @myDecimalValue) | |
/** Output **/ | |
----------- | |
4521312 | |
DECLARE @msg VARCHAR(200) = '' | |
SET @msg = 'The Customer already exists!' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DROP TABLE Invoices; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ALTER TABLE "Order" ADD CONSTRAINT FK_Order_Customer FOREIGN KEY (CustomerId) REFERENCES Customer(Id); | |
GO | |
ALTER TABLE "Order" DROP CONSTRAINT FK_Order_Customer; | |
GO |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ALTER TABLE Customer ADD RFC VARCHAR(13) NULL; | |
GO | |
ALTER TABLE Customer ALTER COLUMN RFC INT NULL; | |
GO | |
ALTER TABLE Customer DROP COLUMN RFC; | |
GO |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DECLARE @intFlag INT | |
SET @intFlag = 1 | |
WHILE (@intFlag <=5) | |
BEGIN | |
PRINT @intFlag | |
SET @intFlag = @intFlag + 1 | |
END | |
GO |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
WHILE boolean_expression | |
{ sql_statement | statement_block | BREAK | CONTINUE } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT ord.CustomerId, | |
cus.FirstName, | |
cus.LastName, | |
Payback = | |
CASE | |
WHEN SUM(ord.TotalAmount) >= 10000 AND SUM(ord.TotalAmount) < 20000 | |
THEN | |
SUM(ord.TotalAmount) * 0.25 | |
WHEN SUM(ord.TotalAmount) >= 20000 AND SUM(ord.TotalAmount) < 30000 | |
THEN |