Tuesday, April 10, 2012

How to model 'toggle' table in sql

I have a table with some columns



CREATE TABLE test (
testid INT,
field1 CHAR(10),
field2 CHAR(10),
field3 CHAR(10),
field4 CHAR(10));


Now I want to be able to have a setting in my app that will allow me to to either enable or disable some of those for particular users.



CREATE TABLE user (
userid INT
);


I was thinking about:



CREATE TABLE user_test_visible (
userid INT,
field1 BOOL,
field2 BOOL,
field3 BOOL,
field4 BOOL);


Also I was thinking about something like this :



CREATE TABLE user_test_visible (
userid INT,
field_name VARCHAR(30),
visible BOOL);


Are any of those approaches sensible?





No comments:

Post a Comment