Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 9 years ago.
Improve this question
I am working on a TVF that is used in multiple stored procedures. How can I find all of the stored procedures that are using that TVF?
You can scour the metadata for mentions of your function, keeping in mind that it can produce false positives if this is a common name mentioned elsewhere or in comments, or miss instances if the function call is built up using dynamic SQL.
SELECT s.name, p.name FROM sys.procedures AS p
INNER JOIN sys.schemas AS s
ON p.[schema_id] = s.[schema_id]
INNER JOIN sys.sql_modules AS m
ON p.[object_id] = m.[object_id]
WHERE m.definition LIKE N'%tvfname%';
There are other ways in 2012, but since the question is also tagged 2005...
I've successfully used this;
SELECT *
FROM INFORMATION_SCHEMA.ROUTINES
WHERE OBJECT_DEFINITION(OBJECT_ID(ROUTINE_NAME)) LIKE '%TVFn%'
It is best to not search the ROUTINE_DEFINITION field of the view as it is capped.
PS - Cannot test on 2005, sorry
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 4 years ago.
Improve this question
I have a bunch of Oracle SQL queries I'd like to prepare some visual model / diagrams for. For example, to show all of the tables, the joins, and the join conditions.
Does such a tool exist?
Yes, Oracle SQL Developer, and it's included with your license of Oracle Database...in other words, it's free.
Bonus, it's Java, so will run on Windows, OS X, and Linux.
Open a connection, this give you a SQL Worksheet.
Type your query, example:
select b.extra_column
,b.department_id
,b.department_name
,b.manager_id
,b.location_id
,c.employee_id
,c.first_name
,c.last_name
,c.email
,c.phone_number
,c.hire_date
,c.job_id
,c.salary
,c.commission_pct
,c.manager_id
,c.department_id
,a.location_id
,a.street_address
,a.postal_code
,a.city
,a.state_province
,a.country_id
from departments b
,locations a
,employees c
where a.location_id = b.location_id
and c.employee_id = b.manager_id
and b.department_id = c.department_id;
Click the Query Builder tab.
Voila.
Note there is a performance bug in current version, will be fixed for version 18.2. In other words, it will take a few moments to render the diagram for you today.
Also this, from the SQL text only with no need to create the tables: https://sqldep.com/
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 6 years ago.
Improve this question
In the past year or so, I have been spending most of time working with noSQL databases. That said, I have started a new job that works with a SQL database and SQL Server Management Studio (SSMS). Any suggestions that would improve readability and make the query more concise would be much appreciated.
SELECT DISTINCT
[db1].[id] as "Node ID",
[db2].[name] as "Node Name",
[db3].[name] as "ISP",
[db4].[name] as "City",
CASE
WHEN [db1].[object_type_id] = 17
THEN 'Client'
WHEN [db1].[synthetic_location].[object_type_id] = 5
THEN 'System'
WHEN [db1].[object_type_id] IS NULL
THEN 'System'
END AS Type
FROM
[db1].[synthetic_location]
JOIN
[db2].[machine] ON [db2].[synthetic_location_id] IS NULL
JOIN
[db3].[internet_service_provider] ON [db3].[id] = [db1].[internet_service_provider_id]
JOIN
[db4].[geography_city] ON [db4].[geography_city].[id] = [db1].[synthetic_location].[geography_city_id]
WHERE
[db2].[status_type_id] < 1
AND [db1].[flags] = 6
Your query looks fine and is perfectly readable with one exception;
You should explicitly state INNER JOIN instead of just JOIN as it makes the intention clearer.
You can use tools like SSMS Boost or SQL complete that will help you to format the queries and those tools have so many additional features that can save lot of your time
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
I'm writing the following SQL query:
SELECT *
FROM OS
WHERE OS.VERSION LIKE '%1%';
In my table there are rows with char 1 in it. However, it returns an empty result.
I changed a little bit the LIKE clause to different values, but it still doesn't work.
What can I do to fix that?
Try double-quotes and * for wildcards. You are using Oracle syntax instead of Access syntax.
LIKE operation can't be used with columns of integer type. I assume that OS.Version is of integer type?
Edit1:
If you are referring to MS Access then you have to do the LIKE with stars (*) instead of %.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Improve this question
What does the "s" do at the end of line 8 of this query:
http://www.sqlfiddle.com/#!3/f8816/20/0
I can't find it anywhere and the statement won't work without it.
Thanks!
The s is an alias for the result set which allows it to be referenced within the query.
The readability of a SELECT statement can be improved by giving a table an alias, also known as a correlation name or range variable. A table alias can be assigned either with or without the AS keyword:
table_name AS table alias
table_name table_alias
Using table aliases
The s is a table alias. It gives a name to a table or subquery used in the from clause.
SQL Server requires that all subqueries use aliases. Not all databases do.
I strongly encourage you to use them. They often make queries much more readable.
The data set getting created in the from is given the name 's' (similar to putting "AS s") so you can reference it otherwise in the code. Any data sets being created in a from requires a name be given to it, hence why it only works with the 's'.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
does anyone know of a way to generate some kind of checksum for each Stored Procedure on a server, in order to be able to compare them to other SP's on different servers?
Regards,
Jeroen
You could;
SELECT
ROUTINE_NAME,
HASHBYTES('SHA1', ROUTINE_DEFINITION)
FROM INFORMATION_SCHEMA.ROUTINES
WHERE ROUTINE_TYPE = 'PROCEDURE'
AND OBJECTPROPERTY(OBJECT_ID(ROUTINE_NAME), 'IsMSShipped') = 0