Friday, February 24, 2012

Import a database into SQL Server.

I need to import an SQL database into SQL express 2005. The database was created with an older edition of Sql Server. I need to import the database onto a server that only supports SQL 2005, and I have the express edition. Can it be done with transact SQL. I know very little about transact SQL and I dont mind very long answer with lots of explination.

hi,

if you have the physical files that made up the database, you can copy them on the new server and "attach" them as a new database... SQL Server Management Studio Express, the free graphical tool you can download from http://www.microsoft.com/downloads/details.aspx?familyid=C243A5AE-4BD1-4E3D-94B8-5A0F62BF7796&displaylang=en provide a simply way to do it.. just right click the "Databases" node, "Attach".. you will be prompted with a dialog where you have to provide the full path of the primary data file of the database you want to attach (.Mdf file).. the transaction log file will be "selected" for you if available in the same folder ... specify the database name as required...

you have then to modify the database owner... refresh the database list, access the relative database "properties" and set the database owner to a valid principal... then go to the "Options" tab and set the database compatibility level to SQL Server 2005 (90)..

you can perform these steps via standard Transact-SQL statements as well..

see the CREATE DATABASE ... FOR ATTACH syntax at http://msdn2.microsoft.com/en-us/library/ms176061.aspx for attaching the database, sp_dbcmptlevel sytem stored procedure at http://msdn2.microsoft.com/en-us/library/ms178653.aspx to modify the database compatibility level and, finally, sp_changedbowner ystem stored procedure at http://msdn2.microsoft.com/en-us/library/ms178630.aspx to set the database owner...

then you have to update statistic, http://msdn2.microsoft.com/en-us/library/ms187348.aspx... for each table in the database perform the update with fullscan: open a query windows and execute the statement for each table...

UPDATE STATISTICS Sales.SalesOrderDetail WITH FULLSCAN;

regards

No comments:

Post a Comment