Articles → SQL SERVER → Views For Data Abstraction

Views For Data Abstraction






What Is An Abstraction?







Scenario




  1. Maintain customer information (i.e., name and address)
  2. Maintain customer payments record
  3. Maintain customer orders
  4. Monthly Reports




customer_idcustomer_namecustomer_address




order_idcustomer_idorder_details




payment_idorder_idpayment_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










  1. Add columns to the table
  2. 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





Posted By  -  Karan Gupta
 
Posted On  -  Wednesday, March 30, 2011

Query/Feedback


Your Email Id
 
Subject
 
Query/FeedbackCharacters remaining 250