Dynamic Table creation

Database
Enthusiast

Dynamic Table creation

HI ,

I  have a typical requirement  for creating a table .

I have an scenario where End users will have an option to select the list of columns for a table .

for this list of columns i need to a create a dynamically .

say  by User-1 selected 3 columns and User-2  selected  5 columns ,then how to create a table dynamically by using stored procedures.

Here end users have an flexible option to select N- number of columns .

im unable to proceed further how to create such a dynamic table and it need to load data daily .

I request all your suggestion to resolve it . Its an important for me .

3 REPLIES
Enthusiast

Re: Dynamic Table creation

Can you please elaborate it furthur . Can we just not have talbe created with all possible columns and then which ever columns user select we can put them in sel query and give it to them.

Enthusiast

Re: Dynamic Table creation

for the first time user -1 selected 5 columns (col1,col2,col3,col4,col5)

then at the first time will create a table with 5 columns

second time user-2 selected 4 columns (col1,col2,col3,col4)

then we need to use the existing col1 to col4 and then needs to insert null for col5

third time user-3 selected 3 columns (col1,col2,col6)

then we need to use col1 and col2 now col6 is not existing we need to add a column to the table .

likewise dynamically users will select the columns
Enthusiast

Re: Dynamic Table creation

Whatever may be the number of columns user selects but is it not predefined like user will be able to see only these number columns on the screen from where he has to select some n number of columns?

Atleast the list of columns which are appearing on the screen should be static right.

If they are statis then we can just form a SQL query from the number of columns selected.