0

View statement

How can I produce a view that rejects an attempt at inserting or updating records

22nd Oct 2019, 1:41 PM
Darren Quinn
Darren Quinn - avatar
1 Answer
0
In SQL Server, there is a setting to make views read only. You can restrict insert, update, and delete permissions on the view. You can also do something like Union a query that returns no results. The union will prevent data modification queries from succeeding because now two tables are involved in the view. For example: Create View ViewName as Select col1, col2, col3 From table Union Select '0' as col1, '0' as col2, '0' as col3 From dual -- This line is for Oracle. It isn't needed in SQL Server Where 1 = 2 -- This will prevent the second union query from returning any results --Just make sure your Union dummy has the same number of columns and datatypes (ints, strings, dates, etc) as the top query.
25th Oct 2019, 4:50 AM
Chris Hansen