Looking for sys.sp_add_ct_history - sql

Context:
I'm investigating a claim that the stored procedure sys.sp_add_ct_history is running and causing some slowness on a particular database after updating to SQL Server 2016 SP3. The only mention from Microsoft documentation just says:
SQL Server 2016 SP3 ...introduced a new table, dbo.MSchange_tracking_history, and a new stored procedure, sys.sp_add_ct_history, to record the history of change tracking cleanup.
This database is indeed using SQL Server Change Tracking on a number of tables, and dbo.MSchange_tracking_history has records. So far, so good.
The issue:
I cannot find sys.sp_add_ct_history anywhere.
EXEC sys.sp_add_ct_history gives a "Could not find stored procedure" error.
I've also tried querying all_objects:
SELECT name FROM sys.all_objects
...and I return various sys stored procedures, but not that one.
Anybody up to speed on this stored procedure? Anything weird about it? Is it extra hidden somehow? Are there permissions I should check for? This doesn't add up and I'm not sure what I'm missing.

Related

Check database / server before executing query

I am frequently testing certain areas on a development server and so running a pre-defined SQL statement to truncate the tables in question before testing again. It would only be a slip of a key to switch to the live server.
I'm looking for an IF statement or similar to prevent that.
Either to check the server name, database name, or even that a certain record in a different table exists before running the query.
Any help appreciated
For such cases I use stored procedures. I'd call them TestTruncateTables, etc.
Then instead of calling TRUNCATE TABLE you should CALL TestTruncateTables.
Just make sure that the procedures are not created on the live server. If by any chance you happen to run CALL TestTruncateTables on the live server you only get an error about non-existing proc.

Stored procedure not compiling with different USE clauses

I have several views in Database 1 and I wrote a stored procedure in database 2. The stored procedure in database 2 references several tables in database 1.
For some reason when I have:
USE Database1
GO
while testing, it works completely fine. But when I use
USE Database2
GO
the stored procedure doesn't compile. No warnings, just continues to spin. The first case only takes about 1 second to run.
Anyone know what could possibly be the issue? When I attempt to run similar stored procedures in database2 that use the same references to database1 it works fine. Also, they are on the same server in SQL Server.
Sorry I am unable to post the code.
SQL Server has to take out locks on the objects so it can create a query plan. It either cannot connect to the database or cannot take the locks it needs.

SQL Server query execution plan for stored procedure references table that does not exist in code

Using Microsoft SQL Server 2012
I have a graphical query plan for a stored procedure. In one part of the procedure the plan makes reference to a table (not a view or function) that doesn't exist within the stored procedure. I've gone through the stored procedure line by line, checked tables to see if triggers had been defined on them and still I can't find the table name the query plan is making a reference to.
Has anyone ever come across this? Is this a bug or am I missing something obvious.
Thanks!

Stored Procedure stopped working

I have a stored procedure that I'm positive of has no errors but I recently deleted the table it references but imported a backup with the same name exactly and same column settings (including identity) that the previous one had but now it doesn't work.
Is there any reason that having deleted the table but importing a new would break the stored procedure?
BTW: Running Microsoft SQL Server Express Edition w/ IIS.
you can try to recompile the stored procedure with:
exec sp_recompile YourProblemTableNameHere
this will recompile all procedures that use the YourProblemTableNameHere table. But that is just a guess based on the very limited info given.

I traced a Stored Procedure as shown in the SQL Server 2005 Profiler. It's not found but works. Why?

This is pretty weird.
I have my Profiler open and it obviously shows that a stored procedure is called. I open the database and the SP list, but the SP doesn't exist. However, there's another SP whose name is the same except it has a prefix 'x'
Is SQL Server 2005 mapping the SP name to a different one for security purposes?
EDIT: I found out it's a Synonym, whatever that is.
In general, when you know an object exists because it's been used in a query, and you can't find it in the object tree in Management Studio, you can do this to find it.
select *
from sys.objects
where name = 'THE_NAME_YOU_WANT'
I just checked, and it works with Synonyms.
Possibly silly questions, but just in case... have you refreshed the SP list? Have you checked for a stored procedure of that name under a different owner? If you created the stored procedure without specifying the owner then it could be in the list under your ownership (or not at all if the list is filtered to only "dbo" for example).
You may not have permission to see all the objects in the database
Adding to the previous answers, it could also be under "System Stored Procedures", and if the name of the stored procedure begins with "sp_", it could also be in the master database.
The stored procedure will be inside the database you have selected at time of stored procedure creation. So search inside the database from which it is extracting data, otherwise it will be inside the master database. If still you are not able to find then first number solution is best one. i.e.
select * from sys.objects where name = 'name of stored procedure'