I have some data in a view which I want to insert into a table (same table schema) what's the easiest, cleanest way to do it.
You can insert data through a single-table view if you have the Insert privilege on the view. To do this, the defining SELECT statement can select from only one table, and it cannot contain any of the following components: DISTINCT keyword. GROUP BY clause.
To insert data through view in multiple tables, we need to use the INSTEAD OF TRIGGER in SQL Server. An INSTEAD OF TRIGGER in SQL Server allows executing other statements specified in the trigger instead of an INSERT, DELETE, or UPDATE statement to a table or view.
if you want to insert the entire column then you can do like
insert into table_name
select * from view_name
Insert Into dbo.MyTable (Col1, Col2,...)
Select Col1, Col2, ...
From dbo.MyView
insert into mytable(c1, c2, c3, ...)
select c1, c2, c3, ... from myview
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With