How to create, modify and store source code efficiently in your development environment using Visual Studio – find out how we handle code management in Polarys Polska.
What is source code management?
Every developer is managing own source code. There are many ways to store your SQLs. Do you know how to do it efficiently in your development environment? Visual Studio is the answer. Visual Studio is an IDE provided by Microsoft and it will support you with managing SQL code.
The good idea
The most simple and very good way to store SQL code is to keep definitions of database objects in text files (with .sql extension) – one file per db object, name file the same as the object name. This is not rocket science, this is a good practice. Keeping good practices is something that distinguishes professionals and allows us to work efficiently. This method allows you to keep orderliness in your projects and gives you a chance to use a version control system for your SQL code. The next level of smart managing your code is to organize those files. Visual Studio provides you with a good tool for this: a database project.
Visual Studio – How VS is managing code?
In a logical sense, a project contains files that include source code like SQL files (definitions of tables, stored procedures, views, etc.), reports definitions (rdl), SSIS packages, etc.
A project is contained within a solution. Despite its name, a solution is not an „answer”. It’s simply a container for one or more related projects.
Visual Studio – Main advantages
- Database structure validation – VS can check syntax, references and relations between DB objects on the fly, it can be a good first part of the code review
- Version control integration – when you are storing db structure in files, you can use version control easily, VS provides an integrated GIT client.
- Running queries (just like in SSMS) – you can connect your VS to the database and run every query directly from your IDE
- Schema comparison – you can compare databases and projects structures
- Code deployment automation – VS provides tools for code deployment
- Data comparison – you can compare data between two databases
- Azure integration – you can see your Azure projects and databases inside VS
How to create a database project?
First, you need to add a new project (Database) to your solution. Then you can add a new item (DB object) or import an existing database from a server directly or import extracted dacpac.
Most SQL developers was starting by scripting DB objects from a server every time they need it. Usually, the next step is to keep some queries or some parts of object definitions in unorganized files. Lack of code management really breaks your work efficiency. If you want to be a professional SQL developer, you must manage your code in a professional way.