Tuesday, March 27, 2012

Basic Insted Of Insert Trigger

I am using SQL 2005.
Could you please give me the most basic Instead Of Insert Trigger for
updating a view composed of two Tables. F0r example:
ProductTable Columns are ProductID (int, key) ProductName (varchar)
ProductAttribute Columns are Attribute1, Attribute2, ProductID.
The View is ViewProductTableProductAttribute :
SELECT dbo.ProductTable.ProductID, dbo.ProductTable.ProductName,
dbo.ProductAttribute.ProductAttribute1,
dbo.ProductAttribute.ProductAttribute2
FROM dbo.ProductTable INNER JOIN
dbo.ProductAttribute ON dbo.ProductTable.ProductID =
dbo.ProductAttribute.ProductID
How would a basic Instead Of Insert trigger work here on the View?
Would I need another view to update data to the two tables?
TIA,
PaoloPaul (PaulContactMe@.TheCornerStore.com) writes:
> I am using SQL 2005.
> Could you please give me the most basic Instead Of Insert Trigger for
> updating a view composed of two Tables. F0r example:
> ProductTable Columns are ProductID (int, key) ProductName (varchar)
> ProductAttribute Columns are Attribute1, Attribute2, ProductID.
> The View is ViewProductTableProductAttribute :
> SELECT dbo.ProductTable.ProductID, dbo.ProductTable.ProductName,
> dbo.ProductAttribute.ProductAttribute1,
> dbo.ProductAttribute.ProductAttribute2
> FROM dbo.ProductTable INNER JOIN
> dbo.ProductAttribute ON dbo.ProductTable.ProductID =
> dbo.ProductAttribute.ProductID
> How would a basic Instead Of Insert trigger work here on the View?
Are you asking us to write the requirement spec for you?
Seriously, you know the tables and the business rules. You may not
the syntax, but you know what you want to happen when you say:
INSERT view (...)
SELECT ...
So give us the CREATE TABLE, some sample data (more than one row!)
and the desired result. And some short description in text of what
you want to happen.

> Would I need another view to update data to the two tables?
A somewhat funny question. That makes me ask, why did you add a
view in the first place? I see little reason to create a second
view for the UPDATE. Then again, I don't know the busines rules.
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pr...oads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodin...ions/books.mspx|||Actually, I am experimenting. I think this is a technology, and am
curious about how it works.
Thanks,
Paul
"Erland Sommarskog" <esquel@.sommarskog.se> wrote in message
news:Xns97F23FEBA187Yazorman@.127.0.0.1...
> Paul (PaulContactMe@.TheCornerStore.com) writes:
> Are you asking us to write the requirement spec for you?
> Seriously, you know the tables and the business rules. You may not
> the syntax, but you know what you want to happen when you say:
> INSERT view (...)
> SELECT ...
> So give us the CREATE TABLE, some sample data (more than one row!)
> and the desired result. And some short description in text of what
> you want to happen.
>
> A somewhat funny question. That makes me ask, why did you add a
> view in the first place? I see little reason to create a second
> view for the UPDATE. Then again, I don't know the busines rules.
>
> --
> Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
> Books Online for SQL Server 2005 at
> http://www.microsoft.com/technet/pr...oads/books.mspx
> Books Online for SQL Server 2000 at
> http://www.microsoft.com/sql/prodin...ions/books.mspx

No comments:

Post a Comment