Using database project and SQL Data Tools in Visual Studio 2012 : How do I get temp tables to resolve? - tsql

I am learning Visual Studio 2012's "database project" system, using Visual Studio 2012 with Update 1, plus SSDT.
I am finding it very good at finding real problems in my database, especially programming errors in stored procedures where someone has removed a field from a database table but didn't go through and verify that all the stored procedures execute without errors. So validation of your .sql scripts via the "build" command in Visual Studio 2012 is very handy. I would hate to abandon it.
But I also note that whenever a #TEMPTABLE is used in a stored procedure, even when "Enable Extended Transact-SQL verification for common objects" is turned off, I still get "build errors" involving #temptable.field references in stored procedures.
What steps does the Database Project take to determine the schema of a temporary table? Since my temporary tables by definition don't exist in the main schema, they didn't get into my Database Project when I imported a real production SQL database into Visual Studio via the Import Database option, right after creating the database.
Should I be creating "#TEMPTABLE.SQL" files and adding them to my project?
Sample error:
c:\dev\...\dbo\Stored Procedures\xyz.sql(95,96): Warning: SQL71502: Procedure: [dbo].[proc123] has an unresolved reference to object [#temptable1].[somefield1].
If there was a way to include a script that defined the temptables in use once, and include it into the various places where it's necessary to know about these if the T-SQL is to be thoroughly validated, that would be fine, and if Turning of Extended Verification did what I think it's supposed to do, then perhaps nothing would be necessary.
Forum post suggests this isn't possible to fix and that all I can do is effectively turn off this warning at a file level, which is kind of horrible.
A question on this same subject but for Visual Studio 2010 suggests that this is an area where this technology has been just flat out broken and Microsoft has known for years about it and done nothing about it. Is anything better now in VS2012.U1+SSDT_Dec2012?

Thats a problem with temp table, you should use table valued functions.

Related

How to check C/C++ code for wrong SQL queries?

I have worked on a Python application that queries a PostgreSQL DB using SQLAlchemy. My DB has a large number of tables many of which get modified every release. Whenever I make a change to a table (say, renaming a column), I execute mypy to find places in the code which are referencing old column names and I fix them in all such places. I now have to write some code using C/C++ and I have used libpq. The problem is that I have to manually scan the code to find places where changes are required whenever I make table changes. This is error prone. Is there a better way to ensure that the C/C++ code is in sync with the DB schema ?

Create foreign key to table that doesn't exist in postgres

I've also asked this question in DBA exchange, but not sure if that is the right place.
I'm trying to put together a solution where I have a bunch of script files that contain my schema creation. Something similar to Visual Studio's SQL Project, but for Postgres.
My problem is that the files won't necessarily be read in the correct order, for instance the first file/script/table read has a dependency on the 2nd file/script/table.
I was hoping there was some way I could disable the check to see if the referred table/column does exist, creating all the tables, and then re-enabling the check.
I'm running 9.2.24
My 2nd solution would be to order the files in such a way that it does only create a table when the dependencies already exist, but my above mention method would be preferred.

Can we see IBM DB2 stored procedure content in AQT(Advanced Query Tool)?

I am not an expert in IBM Host tools as I am from development distributed side. Is there anyway that we can see the source code of IBM DB2 stored procedure in AQT tool. I know we can use any emulator tools like Attachmate Extra! X-treme, but the process seems very tough for me. To view a single stored procedure content, I had to type many number of commands. So I just thought it would be great if we have an option to view the same in a simple way, like we have sp_helptext in SQL SSMS (SQL Server Management Studio).
Update:
When I go to the Database Objects -> Procedures, all the schema's for different stored procedures are loading. And when I click on each schema, the stored procedures associated with that are loading, where I am able to see the procedure parameters, run procedure, create procedure etc. But I couldn't find any option to see the actual SQL query of the procedure.
When I click right click on procedure name and select View, I am getting options as,
Procedure Details
Procedure Params
User Access List
Package Access List
I am not seeing any option like Procedure Text. The language in Procedure Detail shows as COBOL and User Access List shows Execute G. Sorry that I can't provide any screenshots here, as it is the client machine I am working on.
Are you using the right tool for the job?
The AQT tool appears to be for procedures that are written in SQL, but your procedures appear to be COBOL stored-procedures. Source code for COBOL stored-procedures is normally managed outside of the RDBMS.
Talk with your DBA team or COBOL developers to find out which toolset at your site gives access to the source code for the COBOL stored procedures.

How can I see the call tree for SQL stored procedures offline (without actually creating them)

I have a huge SQL script which i need to analyse. It would be really helpful if i could find a way which can generate a call tree; ie, to see which all procedures are called from a particular procedure. a perl based example is here, http://sqlblog.com/blogs/linchi_shea/archive/2009/10/23/find-the-complete-call-tree-for-a-stored-procedure.aspx
but i need a tool to analyse the text file (.sql file), not the procedure stored in the database. due to some reasons i will not be able to create the whole set of procedures in the database and use the above mentioned tool.
please respond if you have come across any ide/tool with this feature.
Probably not very helpful, as it violates your request for a "offline" sql file, text based parsing tool, but wanted to throw this redgate tool out there that I have used with great success in the past; RedGate Sql Dependency Tracker. It works very well and does a good job mapping out your objects and all their dependencies (definable as to what you want mapped). But it does require a database with all of the existing objects in place to work properly. :(
If you can't find one out there, I guess you could maybe do some script/macro text parsing if all the procedure calls are easily defined and predictable in the file. AutoHotKey is a great general purpose scripting tool/framework, and there are a few sql based scripts out there...just not one exactly like you are looking for that I have seen.

A plugin like "Resharper" for SQL Server Management Studio?

Does anybody know of a program or plugin for SQL Server Management Studio which is like Resharper for MS Visual Studio?
For example, it would be great to enter Ctrl-Shift-N and after starting to enter the name of a stored procedure to see list of stored procedures with most general commands like - alter, drop and create.
Look at the ApexSQL refactor, it is FREE amazing add-in for Visual Studio and SQL Management Studio. http://www.apexsql.com/sql_tools_refactor.aspx
You can try SQL Prompt by redgate
I came across another interesting plugin called SqlSmash. It works with SSMS 2012 and is free for now it looks like.
Features from the website:
Go To Object: Easily navigate to any of the tables, stored procedures, functions or triggers in any of your databases.
Format Sql: Apply your casing preferences to the keywords, variables and identifiers and indent the Sql.
Execute Current Query: Only execute the query that your cursor is placed at.
Search Objects: Search all your database objects for any text.
Summarize Script: Summarize complex scripts and navigate around easily.
Go To Definition: Show the definition of a Sql object quickly.
Find All References: Find what other objects are referencing the Sql Object under your cursor.
Quick Info: Get a quick overview about the Sql Object under your cursor.
I don't think it has that autocomplete feature you've mentioned (which is in MS Management Studio >= 2008) but the "SSMS Tools Pack" add-in has some other features you might be interested in:
http://www.ssmstoolspack.com/
Features:
SQL Snippets
Window Connection Coloring
Window Content History, Query Execution History and Current Window History
Format SQL
Search Table, View or Database Data
Run one script on multiple databases
Copy execution plan bitmaps to clipboard or file
Search Results in Grid Mode
Generate Insert statements from resultsets, tables or database
Regions and Debug sections
Running custom scripts from Object Explorer
CRUD stored procedure generation
New query template
General options