0
votes

I am using sql to create tables in my database in order to support different configurations.Columns in my table has same column name but different data types. For Example

First Configuration: Table contains column Field with type int

Second Configuration: Table contains column Field with type varchar(255)

Third Configuration: Table contains column Field with type char

In order to support the 3 different configurations my database should have all the three fields.

My Create script is:

CREATE TABLE P1
(
Field  int,
Field  varchar(255),
Field char

);

But this gives error due to duplicate column name. Is there a work around for this problem or is there a better design that can be followed.Please suggest.

1
what kind of data are you storing in these columns? can they be split into different tables for different combinations? can you provide sample data for your configurations and how they are used. Also mysql <> postgresql <> sql server. pick oneughai
@ughai...thanks...I am using postgresqlcodingBliss
For one table, the column names have to be unique. You can't have three columns with the same name. There is no workaround for this (btw: you don't need to two character columns - varchar and char are the same from a performance point of view)a_horse_with_no_name

1 Answers

0
votes

You can't define the same column three different ways. To do something resembling what you want, you'd have to do something like

CREATE TABLE P1 (
Field_int  int,
Field_varchar  varchar(255),
Field_char char
);