sometimes i face the following case in my database design,, i wanna to know what is the best practice to handle this case:::
for example i have a specific table and after a while ,, when the database in operation and some real data are already entered.. i need to add some required fields (that supposed not to accept null)..
what is the best practice in this situation..
make the field accept null as (some data already entered in the table ,, and scarify the important constraint )and try to force the user to enter this field through some validation in the code..
truncate all the entered data and reentered them again (tedious work)..
any other suggestions about this issue…
The best way to go about it is to truncate the data and re – enter it again, but it need not be too tedious an item. Temporary tables and table variables could assist a great deal with this issue. A simple procedure comes to mind to go about it:
In SQL Server Management Studio, Right – click on the table you wish to modify and select
Script Table As>CREATE To>New Query Editor Window.Add a
#in front of the table name in theCREATEstatement.Move all records into the temporary table, using something to the effect of:
INSERT INTO #temp SELECT * FROM originalThen run the script to keep all your records into the temporary table.
Truncate your original table, and make any changes necessary.
Right – click on the table and select
Script Table As>INSERT To>Clipboard, paste it into your query editor window and modify it to read records from the temporary table, usingINSERT .. SELECT.That’s it. Admittedly not quite straightforward, but a well – kept database is almost always worth a slight hassle.