0

I was working on a project where i made a database on sql server 2008 using visual studio 2010 and i took backup of that databse by right clicking on it in sever explorer and selecting "Publish to Provider" that creates a .sql file in my computer that i taken. Previously i formatted my pc and sql server databases are lost, so now i want to use that .sql file to recreate the database with all data, but i don't know how it can be possible.

Something i tried but it created all tables in master database but i want the database of the name i.e. stored in .sql file or specified by me.

Please help.

2 Answers 2

2

First Create a Database using this,

Create Database YOURDBNAME

Here, YOURDBNAME = DataBase Name

Then, Open your .sql file write this in First line of the .sql page,

Use YOURDBNAME

Now press F5, all the tables and data will be created and inserted.

Sign up to request clarification or add additional context in comments.

2 Comments

but in output it shown this (1 row(s) affected) for many times, do this shows i lost some data please reply.
that message is the conformation for the rows that are inserted in tables.
0

You can use the SQL Server Management Objects libraries to manage all aspects of SQL Server.

SQL Server Management Objects (SMO) is a collection of objects that are designed for programming all aspects of managing Microsoft SQL Server. SQL Server Replication Management Objects (RMO) is a collection of objects that encapsulates SQL Server replication management.


From your description, however, this can be overkill. You get simply use SQL Server Management Studio (link goes to the free Express edition download), connect to the server, open a new Query Window with your SQL file and run it (F5).

2 Comments

Is it possible to do the same using command prompt or Visual Studio. Because i have very slow internet connection and that SSMS file will take atleast 5 hours to me to download. If possible please tell me other ways using Visual Studio 2010.
@user1306589 - Not sure this will work, but if you use the Server Explorer and open a new query on the server you need, you may be able to paste the SQL into the Query portion and run it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.