Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

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?

share|improve this question
    
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 Jun 15 '13 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 Jun 22 '13 at 22:11

1 Answer 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 ....
share|improve this answer
    
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 Jun 15 '13 at 17:19

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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