|
database
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Basic Insted Of Insert TriggerCould 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, Paolo Paul (PaulContac***@TheCornerStore.com) writes:
Show quote > I am using SQL 2005. Are you asking us to write the requirement spec for you?> > 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? 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 aview 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, esq***@sommarskog.se Books Online for SQL Server 2005 at http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx Books Online for SQL Server 2000 at http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx Actually, I am experimenting. I think this is a cool technology, and am
curious about how it works. Thanks, Paul Show quote "Erland Sommarskog" <esq***@sommarskog.se> wrote in message news:Xns97F23FEBA187Yazorman@127.0.0.1... > Paul (PaulContac***@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, esq***@sommarskog.se > > Books Online for SQL Server 2005 at > http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx > Books Online for SQL Server 2000 at > http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx |
|||||||||||||||||||||||