Articles → SQL SERVER → Views For Data Abstraction
Views For Data Abstraction
What Is An Abstraction?
Scenario
- Maintain customer information (i.e., name and address)
- Maintain customer payments record
- Maintain customer orders
- Monthly Reports
customer_id | customer_name | customer_address |
---|
| | |
order_id | customer_id | order_details |
---|
| | |
payment_id | order_id | payment_details |
---|
| | |
create procedure sp_get_customer_information As begin
select
customer_id,
customer_name,
customer_address
from
tbl_customer_information end
create procedure sp_get_monthly_reports As begin
select
ci.customer_id,
ci.customer_name,
ci.customer_address,
co.order_details
from
tbl_customer_information ci
inner join tbl_customer_orders co on ci.customer_id = co.customer_id end
- Add columns to the table
- Change all the stored procedures where you have used the table earlier
create view v_customer_information as
select
customer_first_name,
customer_last_name,
customer_city,
customer_state
from
tbl_customer_information
create procedure sp_get_monthly_reports As begin
select
ci.*,
co.order_details
from
v_customer_information ci
inner join tbl_customer_orders co on ci.customer_id = co.customer_id end