I have one scenario in which the user can define the column and that can be the master table. This master table has transaction table by ref its Primary key and also has some common column whose value is differ for each record.
Example,
user created table called XYZ and defined the column X1,X2,X3 etc,. And the Transaction table as Tran_XYZ and it contains ref to the XYZ and also the Column X1,X2,X3 whose values are override here.
I need to implement this dynamic column in asp.net please suggest me the best technology and method to follow.
Hmm, I’m not sure that I have a great answer for you regarding what you should do, but I would recommend against having your application use DDL to dynamically create actual tables in your database. Not to say that it should never be done, but I would say 99% of the time it’s probably not a good idea.
Is the transactional table also dynamically created? Are all of the records in that transactional table going to be related to this master table that the user is creating, or will some of the records in that transactional table be related to other master tables that other users have created as well?
If there is only one transactional table that will need to have references to multiple user-defined master tables, then I would consider having a core transactional table that does not have any columns referencing these user-defined master tables. Then I would have another table in a 1-to-1 or 1-to-many relationship with that transactional table that does have references to the appropriate master tables.
As I mentioned above, I would consider not creating actual tables in the database to represent user-defined master tables, though. I would consider an approach like the following with SQL Server 2005 or later:
EDIT: fixed my formatting.
So the TransactionalUserDefinedData table is in a 1-to-many relationship with the TransactionalData table, which is the core transaction table. The TransactionalUserDefinedData relates a transactional record with 0, 1, or more user-defined master tables. The XML column on both the UserDefinedMasterData table and the TransactionalUserDefinedData tables allows you to dynamically specify “columns” of data.
I left the Data column in the TransactionalUserDefinedData table as nullable, thinking that a null value in that column would indicate that the data from the master table is not overridden and the data from that table should be used for this record.
If you do not want to allow a transactional record to be related to multiple user-defined master tables as in my example, then you can either change the primary key on the TransactionalUserDefinedData table to be only the TransactionID column, which changes that table’s relationship to the TransactionalData column from 1-to-many to 1-to-1, or just move the columns from the TransactionalUserDefinedData table into the TransactionalData table.