开发者

Inheritance Problem in SQL Server 2005

I am having a problem whose solution I can't seem to figure out at the moment. Say I have a table

CREATE TABLE #Test
(
     SomeValue1 INT,
     SomeValue2 INT
)

Now, I have two other tables, say TableA and TableB, in which TableB inherits from TableA by sharing its开发者_如何学Go primary key. I want to insert SomeValue1 into TableA and SomeValue2 into TableB, but in a way such that when you join TableA and TableB by their primary key you get #Test, but I can't figure out how to do it. Can anyone please help me?


SELECT SomeValue1, SomeValue2 FROM TableA A JOIN TableB B ON A.PrimaryKey=B.PrimaryKey

That sounds like what you're asking for, from what I can tell. Maybe you're also saying you want to create a View on the two tables of existing data?


If TableB inherits I assume TableB has the foreign key to an IDENTITY column in TableA

INSERT TableA (SomeValue) VALUES (SomeValue1)
INSERT TableB (SomeValue) VALUES (SCOPE_IDENTITY(), SomeValue2)

Otherwise, you can adapt the OUTPUT clause from your other recent questions: Output to Temporary Table in SQL Server 2005

Note:

How does this relate to Iterating Through Table in High-Performance Code? What is your actual end to end requirement... you are asking very specific questions that probably don't really help

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜