Identifying a tablename by interpreting a GUID-Column

  • I have the following problem:

    I have some tables like this:

    CREATE TABLE [tblA]

    (

    [AID] UNIQUEIDENTIFIER CONSTRAINT DF_tblA_AID DEFAULT NEWSEQUENTIALID() ROWGUIDCOL,

    [ALK] NVARCHAR(5) NOT NULL,

    [APLZ] CHAR(5) NULL

    CONSTRAINT PK_tblA_AID PRIMARY KEY ([AID])

    )

    CREATE TABLE [tblB]

    (

    [BID] UNIQUEIDENTIFIER CONSTRAINT DF_tblB_BID DEFAULT NEWSEQUENTIALID() ROWGUIDCOL,

    [BLK] NVARCHAR(5) NOT NULL,

    [BPLZ] CHAR(5) NULL

    CONSTRAINT PK_tblB_BID PRIMARY KEY ([BID])

    )

    and so on.

    further I have one table like this:

    CREATE TABLE [tblWV]

    (

    [WVID] INT NOT NULL,

    [WVVorgangIdent] UNIQUEIDENTIFIER NULL

    )

    Each tblWV.WVVorgangIdent represents either AID or BID and so on.

    Now I want to identify the tablename (in this case 'tblA' or 'tblB') by interpreting one record of the table 'tblWV' having the guid-value:

    WVVorgangIdent= '5F9EA007-D84C-E111-AB31-000C2932980A'

    Is there a posibility deep inside the system-tables?

    I don't want to introduce an mark-up field to mark the type of the GUID (WVVorgangIdent)!

    Thanks for your help!

  • I would use a view for this. OUTER JOIN both tables and define a column "RecordSource" based on which base table contains the ID.

    -- Gianluca Sartori

  • A view can do the trick but for big tables I can choose to add a column to tblWV to flag the source table.

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply