Visual Studio Database Schema Compare Adds not showing up - sql-server

I'm setting up a new SQL Server Database Project for the first time using an existing database. I created my new project, then imported the database and it worked just fine.
However when I add a new stored procedures to my new Database Project and then do a Compare Schema to my local database, the Add of the new stored procedure doesn't show up.
To be clear, when running the Compare I'm setting my source to my Database Project and target to my local database.
The Compare Schema works great for modifications or deletions of stored procedure scripts in my Database Project just not when I define a new one. Am I missing something? Why don't new stored procedures define in my project show up in the comparison results?
I'm using VS2013, SQL Server 2008 R2.

It turns out when I created the stored procedure in Visual Studio I chose the Script... option instead of the Stored Procedure... option. The image below shows what I should have done.
Add the file as a Script resulted in the .sql file being added to a different ItemGroup in the project with no build properties. This is what caused the comparison to not pick it up as a stored procedure.
I determined this by looking at the properties of the .sql file (in Visual Studio) that I added and another .sql in the same project where the comparison worked. The file I added as a Script file had different properties than other files that were being treated as real stored procedures.
Moral of the story... make sure you add stored procedures in Visual Studio correctly.

Related

Multiple CLR schemas in Visual Studio SSDT project

I'm trying to have a single sqlproj project in Visual Studio 2022, representing my SQL Server database.
When creating a CLR stored proc or function in C#, the SqlFunction or SqlProcedure attribute has a Name property, but not a schema. It seems the entire project will use the default schema. I'd like to be able to have more than one schema with CLR items.
I've found a couple different ways of moving procs from one schema to another after deployment, but is there any way to get it right in the first place?
For example, by default, if I create a MyProc procedure, I can reference it as dbo.MyProc from a regular proc. But I want that to live in the other schema. Even if I change schemas as a post-deploy step, then my regular procs with EXEC [other].[MyProc] will not compile properly in Visual Studio since it thinks it's referencing a non-existent procedure.
I don't want multiple projects because I want fully-functional schema compare and publish steps for the whole database.

How to import Table and Data to SQL Server Database Project in Visual Studio 2019

So, I have a solution file which consists of a ASP.Net MVC Application and a SQL Server Database Project. Both are checked in to TFS. I know how to import the database, table, views, functions and stored procedures, but I want to the tables to have data as well. How can I import the table with data?
You can define scripts to run as part of a sqlproj that will insert data into tables. I've seen it used for inserting basic configuration data.
In the Solution Explorer, right click your project and go to Add, then Script. Choose a Post Deployment Script or a Pre Deployment Script. Doing so will add a .sql file to your project, and set the build action appropriately so that it will either run before or after your schema has been created. In this case since you want to add data, you need a Post Deployment Script. If you need to control the order in which data is added, you can add it all in the same file, or just add a single post deployment script and have it invoke other .sql files.

Tables and stored procedures not getting included in the generated script

I have created a SQL Server database project using Visual Studio 2015. The underlying database is SQL Server 2016. I have created the project by importing an existing database into the project. I have the structure ready. When I click on publish and select generate, it doesn't include the tables and stored procedures in the generated script. I can see one odd script added. Am I missing something?
Please see the screenshot of my project
The issue has been now resolved. The mistake i was making is importing the data objects from the database and trying to generate the script pointing to the same database. It was not generating the scripts since the database objects existed . Pointing to another database helped me generating the scripts.

SQL Server database project - Create change scripts

We started using SQL Server database project in Visual Studio 2012 by connecting an existing database. We are developing a web application that connects with this database.
Now we have around twenty stored procedures updated for the next release. How can I create a script file that contains only the updated stored procedures? We need to send this script to our clients along with the Web application executable files.
Is there any feature that allows us to compare and create only the changed scripts?
Thanks in advance!
Use Schema Compare as follows:
Create a Schema Comparison that compares the database project to one of the production databases.
Run the schema compare.
Exclude everything except for the stored procedures (plus any objects on which they depend).
Click Generate Script.
If you save this Schema Comparison then you can reuse it the next time you need to publish more stored procedure changes.

Create Sql server 2008 Huge database script

I have a about 250 SQL script files included tables, stored procedure, user define function, triggers scripts.
I use these files to create and update old database. i want to enhance the time of creation cause it takes very long time to complete. is there more efficient way to create new database with all needed script indexes, triggers, views, SP, UDF.. or way to speed up the creation time.
Just import the scripts into a New SQL Server Database Project in Visual Studio and do a 'Deploy' of the Database Projects after setting up the connection strings properly.
See:
How to: Import Database Objects from a Script. and
Creating A Sql Server Database Project In Visual Studio 2012..
Are you using SQL Server Data Tools? These tools allow you to point your Visual Studio solution at a DB instance and it will generate you a Diff file, based on your DB projects contents.

Resources