1

In SQL, I would like to create a table which can contain generic data types. This types can change from every row. The solution I could come up to is:

CREATE TABLE TagValue
(
     tag VARCHAR(64),
     value BLOB,
     type INTEGER,
     PRIMARY KEY(tag)
);

Here in the 'type' column I put the type of data contained in value.

Is there a better solution?

2
  • What concrete database system? More advanced things like blob store are not part of "core" SQL query language - but they are highly vendor-specific - so we need to know what database this is for
    – marc_s
    Commented Jun 15, 2013 at 19:08
  • @marc_s: The DB I am going to use will probably be PostgreSQL, but my question does not intend to be database specific.
    – Pietro
    Commented Jun 22, 2013 at 22:11

1 Answer 1

1

Why BLOB ? Why not string or varbinary(max) or nvarchar Dot Net Nuke in their database inside table UserProfile have generc column

CREATE TABLE [dbo].[UserProfile](
    [ProfileID] [int] IDENTITY(1,1) NOT NULL,
    [UserID] [int] NOT NULL,
    [PropertyDefinitionID] [int] NOT NULL,
    [PropertyValue] [nvarchar](3750) NULL,
    [PropertyText] [nvarchar](max) NULL,
    [Visibility] [int] NOT NULL,
    [LastUpdatedDate] [datetime] NOT NULL,
    [ExtendedVisibility] [varchar](400) NULL ....
1
  • I put a BLOB in case I have to store, e.g., an integer or an image. Does it have issues with space in case of small data values?
    – Pietro
    Commented Jun 15, 2013 at 17:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.