Friday, 14 June 2013

Update view with single table

Hi,
      In privious article I have discussed about Basic of view . Now we will discuss about a how
to create a view on single table and how to update data or records in table by using view.
example::

create table emp_master (emp_id int identity(1,1) ,emp_name varchar(100),emp_sal varchar(100) ,dept_id int)

Insert records in table::


insert into emp_master (emp_name,emp_sal,dept_id ) values('sandipG','1000',1)
insert into emp_master (emp_name,emp_sal,dept_id ) values('ajit','45321' ,1)
insert into emp_master (emp_name,emp_sal,dept_id ) values('pranav','5000',2)
insert into emp_master (emp_name,emp_sal,dept_id ) values('aditya','10000',3)


1)Create view on single table with select all columns in table .

Create view [dbo].View_on_single_table_1
as
select * from emp_master


Test Case 1::

update View_on_single_table_1 set emp_name ='sachin',emp_sal='2123',dept_id=5 where emp_name='sandipG'
select * from emp_master


Related Posts::

basic of view
insert into view with multiple tables Insert into view with single table Instead of update trigger and after update trigger in sql
Instead of Insert trigger and after insert trigger in sql
instead of delete trigger and after delete trigger in sql
basic of trigger and interview quetions on trigger

No comments:

Post a Comment

8451831077