Sent: Thursday, 11 February 2010 11:34 AMTo: Venkatesan Prabu JSubject: SQL server 2005 help
Hi Venkatesan,
I am member of dot net spider and I require a help from you.
Please provide your help in this regard.
Recently, I went for an interview where they asked me this question
Question: Assume that I have a flat file with more than a million records. I have to insert this in the production database without performance hit for the users? The application is a 24 X 7 application.
My answer: Since we want to do the insert in production database, we would check if there are any maintenance window available. If one is available we would do it during the window by using bulk copy or import data or some schedule job which would read the file and insert into the table.
But the interviewer asked me how do you do it when there are no maintenance window. my answere now was, it is risky to do in production database when users are using the application. But still if you want to continue, try inserting small chunks (say 1000 records). Lock the table, insert 1000 records and release the lock, so that the user would not feel the performance hit.
But still the interviewer was not convinced and expected something more.
Since i am new to sql server 2005, can u pls help me by giving a solution to this scenario.
Thanks
Saravanan---------------------------------------------------------------------------------------------Sent: Mon, 1 March, 2010 3:55:10 PMSubject: RE: SQL server 2005 help
Dear Saravanan,
Your answer is not correct.
1. You should not lock the table which is available for 24/7.
2. You should have another table(With same schema and everything) with all the data from the existing table. Insert all the records into the table.
3. Rename the existing table with temp in the prefix.
4. Rename the new table with old table using sp_rename option.
Probably, I will post a detailed explanation in my blog. Hope, you are happy with this explanation.
Thanks and Regards,
Venkatesan Prabu .J
Microsoft SQL Server MVP/HCL SQL Knowledge Champion/DNS MVM Award Winner
MCITP/MCTS/MCAD/CCNA/QAI
B.B Certified Asp.net/C#/RDBMS/Networking professional
E.R certified Networking candidate
http://venkattechnicalblog.blogspot.com/----------------------------------------------------------------------------------------------
Sent: Thursday, 4 March 2010 12:15 PMTo: Venkatesan Prabu JSubject: Re: SQL server 2005 help
Dear Venkatesan,
Thanks a lot for your reply.
I really appreciate in taking your valuable time to respond to my query.
However, i have one doubt in your solution. If we do the manipulation in the temporary table, any transaction that happened to the original table would be lost right.
Thanks
Saravanan----------------------------------------------------------------------------------------------Sent: Thu, 4 March, 2010 2:47:17 PMSubject: RE: SQL server 2005 help
Dear Saravanan,
That's a very nice question.
For this kind of huge work, always there will be a little hickup which we can't control.
considering the table name is VenkatTable.
1. Put your table as VenkatTable_New
2. Rename the existing table as VenkatTable_Old
3. Rename the table VenkatTable_New as VenkatTable.
4. Migrate the new data from VenkatTable_Old to VenkatTable.
Problem arises, If you have constraints. In that case,
1. Disable the constraints before doing this and enable the constraints after your process.
Enjoy....
Thanks and Regards,
Venkatesan Prabu .J
Microsoft SQL Server MVP/HCL SQL Knowledge Champion/DNS MVM Award Winner
MCITP/MCTS/MCAD/CCNA/QAI
B.B Certified Asp.net/C#/RDBMS/Networking professional
E.R certified Networking candidate
http://venkattechnicalblog.blogspot.com/-----------------------------------------------------------------------------------------------
Dear Venkat,
Thanks a lot for your response. That gave me a good idea.
Thanks
Saravanan