Table structure update capability

Topics: Developer Forum
Aug 29, 2007 at 10:36 AM
Edited Aug 29, 2007 at 12:13 PM
Another quiestion i have about the code is about table structure update. So in addition to Create/DropAndCreate there would be something like UpdateOrCreate method. That would be very usefull for projects that require to load some initial data into DB.

Aug 29, 2007 at 2:35 PM
I am not implemented update table structure because it has a defect in it:

If the new structure have a new column and not allow null. But there are some rows in the old table, the data should be deleted so the new structure could be create, but is it the real perpose of the developer?

And the tables almost always have rows, so if I implement this feature, it will drop the old table and create the new.

Another reason is to get the old structure from database is not very easy.

Do you still think it usefull now?
Aug 29, 2007 at 3:32 PM
I think that theorethicly this might be a very usefull feature, for larger, long term projects, however I realize the complexity of the task, i have a rought idea about how to implement this on SQL Server, but not other databases. If i will be working on a project that requires this feature, i will try to implementy it, and will share the code.
Aug 29, 2007 at 4:11 PM
Ok, it will be added to work item.
But I don't know when it will be implemented.
And, in my plan, it is not using "alter table" to implement.
Aug 29, 2007 at 4:12 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
Aug 30, 2007 at 2:31 AM
Edited Aug 30, 2007 at 2:31 AM
It seems it should be
  1. If the table doesn't exist, then create it.
  2. If all matched, do nothing.
  3. If the diffence could using "ALTER TABLE" to solve, then do it.
  4. If the diffence could not using "ALTER TABLE" to solve, then throw an exception.
Aug 31, 2007 at 5:20 AM
Yes, I think so too, i realize that it might be a difficult task thought, especially to support different databases.