In this article, we will look into a new feature of Visual Studio 2012 to connect SQL databases hosted locally or on SQL Azure using SQL Server Object Explorer. In Visual Studio 2012, we can connect to a database using Server Explorer or SQL Server Object Explorer. Using this explorer, we can perform:
- Connection to and browsing various objects like tables, views, functions and so on.
- Create\Update\Delete objects using Table Designer.
- Clone an existing database.
We can open this window by going to "View" -> "SQL Server Object Explorer" as shown below:
Click on "Add SQL Server" to add an SQL Server instance.
We can add a new table using Table Designer by clicking on "Add Table" on the Tables node as shown below:
We need to click on Update to open the following window and select the "Update Database" button to reflect the changes done by us onto an actual database as shown below:
We can clone a database using the following procedure:
- Create a blank database by clicking on "Add New Database" onto which, it needs to be cloned.
- Now click on "Compare Schema" by selecting the source database:
- Select target as newly created database and click on "Compare", that shows the following differences:
- Click on "Update" to clone the database, that only clones the schema, not the data.
- We can replicate data by selecting a table, clicking on "View Data" and clicking on "Script" as shown below:
- This will create Insert scripts necessary for replicating the data onto a new database:
- We can even look at estimated and actual execution plans of a SQL query by clicking on something.
Using this feature, we can do most of our SQL Server tasks within Visual Studio 2012 itself.