all groups > sql server new users > march 2006 >
You're in the

sql server new users

group:

Modifying Data in a View


Modifying Data in a View James_101
3/28/2006 12:10:03 PM
sql server new users: I am developing a database on my desktop using Developers Edition of SQL
Server 2000. The database will ultimately be sent to my client to run on his
db server. I would like for a specified employee at the client to be able to
modify data, add records and delete records.

I understand that these actions can be taken using a view. I created a view
in Query Analyzer with this code:

USE DatabaseName
GO
CREATE VIEW ViewName
AS SELECT * FROM TableName
GO

I ran the view in Query Analyzer. The view looks OK but I am unable to
modify data. I am the administrator on my desktop. What should I do
differently?

Thanks.

Re: Modifying Data in a View James_101
3/28/2006 3:31:01 PM

[quoted text, click to view]

There is a primary key in the table.

[quoted text, click to view]

Thanks for the info on "SELECT *.

In running the view again, I notice "Read-only" in the title bar of this
view and all other views that I have created. I assume that this is a
permissions issue so I'm reviewing database permissions.

Re: Modifying Data in a View James_101
3/28/2006 7:19:01 PM
I am now able to modify, add and delete records in Views while in Enterprise
Manager. In Query Analyzer, however, when I run the same view, the title bar
displays the name of the view followed by "Read-only". I can select a cell
in the view but the cursor doesn't appear in the cell.

Why can I place the cursor in a cell in a view in Enterprise Manager but not
in Query Analyzer?

Thanks.

Re: Modifying Data in a View David Portas
3/28/2006 9:21:12 PM
[quoted text, click to view]

What does "unable to modify data" mean? Do you get an error message and if
so what is it?

One reason may be that you don't have a primary key or unique index on this
table. QA doesn't allow you to modify the data unless you have a unique key.

Do not use "SELECT *" in any production code, especially not in views.
SELECT * is generally bad because it harms performance and makes code harder
to maintain. It is also dangerous in a view because the view won't refresh
the column list if the table changes. If you drop and then add a column or
if you rename a column then you'll find you get phantom columns in the view
with the wrong name.

--
David Portas, SQL Server MVP

Whenever possible please post enough code to reproduce your problem.
Including CREATE TABLE and INSERT statements usually helps.
State what version of SQL Server you are using and specify the content
of any error messages.

SQL Server Books Online:
http://msdn2.microsoft.com/library/ms130214(en-US,SQL.90).aspx
--

AddThis Social Bookmark Button