Skip to content

Instantly share code, notes, and snippets.

View ArCiGo's full-sized avatar
🎯
Learning

Armando Cifuentes ArCiGo

🎯
Learning
View GitHub Profile
/** Adding constraint to an existing table **/
ALTER TABLE "Order" ADD CONSTRAINT FK_ORDER_REFERENCE_CUSTOMER FOREIGN KEY(CustomerId) REFERENCES Customer(Id);
GO
/** Adding constraint to an existing table **/
ALTER TABLE Customer ADD CONSTRAINT UQ_Customer_RFC UNIQUE(RFC);
GO
CREATE TABLE #tmpTable(
Name CHAR(30),
SeqId INT
);
GO
SELECT cust.Id,
cust.FirstName,
cust.LastName,
cust.Phone
INTO #tmpCustomers
FROM Customer cust
WHERE cust.City = 'Portland' OR cust.city = 'San Francisco';
GO
SELECT "column_name1"[,
"column_name2"
...]
FROM "table_name";
GO
SELECT cus.FirstName,
cus.LastName
FROM Customer cus;
GO
/** Output **/
FirstName LastName
---------------------------------------- ----------------------------------------
Paolo Accorti
Pedro Afonso
SELECT "table_alias"."column_name1" AS "column_alias"
FROM "table_name" AS "table_alias";
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
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
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