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
/** Adding constraint to an existing table **/ | |
ALTER TABLE "Order" ADD CONSTRAINT FK_ORDER_REFERENCE_CUSTOMER FOREIGN KEY(CustomerId) REFERENCES Customer(Id); | |
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
/** Adding constraint to an existing table **/ | |
ALTER TABLE Customer ADD CONSTRAINT UQ_Customer_RFC UNIQUE(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
CREATE TABLE #tmpTable( | |
Name CHAR(30), | |
SeqId INT | |
); | |
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
SELECT cust.Id, | |
cust.FirstName, | |
cust.LastName, | |
cust.Phone | |
INTO #tmpCustomers | |
FROM Customer cust | |
WHERE cust.City = 'Portland' OR cust.city = 'San Francisco'; | |
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
SELECT "column_name1"[, | |
"column_name2" | |
...] | |
FROM "table_name"; | |
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
SELECT cus.FirstName, | |
cus.LastName | |
FROM Customer cus; | |
GO | |
/** Output **/ | |
FirstName LastName | |
---------------------------------------- ---------------------------------------- | |
Paolo Accorti | |
Pedro Afonso |
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 "table_alias"."column_name1" AS "column_alias" | |
FROM "table_name" AS "table_alias"; |
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 * | |
FROM [ORDER] ord | |
WHERE ord.OrderDate BETWEEN '20130101' AND '20130228'; | |
GO | |
/** Output **/ | |
Id OrderDate OrderNumber CustomerId TotalAmount | |
----------- ----------------------- ----------- ----------- --------------------------------------- | |
153 2013-01-01 00:00:00.000 542530 19 3063.00 | |
154 2013-01-01 00:00:00.000 542531 65 3868.60 |
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 * | |
FROM Customer cus | |
WHERE cus.FirstName LIKE 'A%'; --All names that starts with A | |
GO | |
/** Output **/ | |
Id FirstName LastName City Country Phone | |
----------- ---------------------------------------- ---------------------------------------- ---------------------------------------- ---------------------------------------- -------------------- | |
2 Ana Trujillo México D.F. Mexico (5) 555-4729 | |
3 Antonio Moreno México D.F. Mexico (5) 555-3932 |
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 * | |
FROM Customer cus | |
WHERE FirstName LIKE 'Maria'; | |
GO | |
/** Output **/ | |
Id FirstName LastName City Country Phone | |
----------- ---------------------------------------- ---------------------------------------- ---------------------------------------- ---------------------------------------- -------------------- | |
1 Maria Anders Berlin Germany 030-0074321 | |
24 Maria Larsson Bräcke |