T-SQL Tutorial

T-SQL Create View


Create View Example

Customers table

CUSTOMER_IDCUSTOMER_NAMECUSTOMER_TYPE
1CUSTOMER_1CC
2CUSTOMER_2I
3CUSTOMER_3SM
4CUSTOMER_4CC

Contracts table

CONTRACT_IDCUSTOMER_IDAMOUNT
11400
22500
33700
411000
521200
64900
732000
821500

CREATE VIEW CustomersList
  AS
SELECT c.customer_id, c.customer_name, ctr.contract_id, ctr.amount
  FROM customers c, contracts ctr
WHERE c.customer_id = ctr.customer_id
     AND c.customer_type='CC' ;

Result:

Customer_IdCustomer_NameContract_IdAmount
1CUSTOMER_11400
1CUSTOMER_141000
4CUSTOMER_46900