views:

33

answers:

2

Hello.

Rightly or wrongly I’m dealing with a generalised SuperType table which I have the sub type data for but not the SuperType data. However to insert the SubType data I obviously need the Identity ID from the SuperType table first.

I was wondering if anyone else has come across this and how they got around it. Unfortunately there is no Type Column in the SuperType table as the SuperType can potentially have two types in the SubType tables. Otherwise I would just populate the type column. Alternatively I thought I could insert a blank Value (not null) to the Super table but this just seems very very wrong.

Am I stuck with this problem or is there a cunning way around it I’m just not seeing?

Many thanks

+1  A: 

Why don't you add a DateCreated column to your SuperType Table?

CREATE TABLE dbo.SuperType
(
SuperTypeId INT IDENTITY(1,1),
DateCreated DATETIME
)
Go
Barry
Hello Barry, that works well. I didn't think of that for some reason because I already have a DateCreated column but with a default GETDATE(). I didn't occur to me to overwrite it. Many thanks for the quick response.
FairFunk
@FairFunk - not a problem. Sometimes all it takes is a second pair of eyes :)
Barry
+2  A: 

Is this Microsoft SQL Server? You don't need to insert any values or have a redundant column. Try this:

CREATE TABLE dbo.SuperType (SuperTypeId INT NOT NULL IDENTITY PRIMARY KEY);

INSERT INTO dbo.SuperType DEFAULT VALUES;

SELECT SCOPE_IDENTITY();
dportas
Thats spot on...and not something I'd seen before actaully. Excellent. This is def something I'll look into further.
FairFunk