Skip to main content

Posts

Showing posts from February, 2013

How to create a read only view

In this specific case the server application I'm working with are using a database hosted by SQL Server. The database is designed to be accessed by the server application alone, but there exists situations when other systems also want information from the database, such as status information. In those cases there is a good idea to create a view that other systems may use, and leave the database's tables to the server application. But also, the view should be read only, making it impossible for other parties to change the information. This can be done in number of ways and below I will show two: Create a read only view CREATE VIEW CustomersView AS   SELECT ID, FirstName, LastName FROM Customers   UNION ALL SELECT 0, '0', '0' WHERE 1=0 Add a union to the create view statement, the columns in the union must match the columns in the select statement. When the user executes an insert, delete or update statement then is the following error received: Msg 4406,