This question already has answers here:
Find a value anywhere in a database
(18 answers)
Drop all the tables, stored procedures, triggers, constraints and all the dependencies in one sql statement
(21 answers)
Search all tables, all columns for a specific value SQL Server [duplicate]
(4 answers)
Closed 8 years ago.
My question might sound stupid, but does there exist a script that could find out where in database, for which tables, is the desired data located? Say for example, i need to found where Texas is located in database, in which tables and in which column.
There exists a script that could find out the tables, SP, views based on the column name provided. Is there any script that could find out tables, column name etc based on the actual data?
Hope the question is understood.
Best Regards
Josh Walker has a script that will find the number of incidences a string of text is found, and in which tables:
http://www.sqlservercentral.com/scripts/Miscellaneous/65769/
And, this statement should find any procedure code that contains the text you are looking for:
SELECT OBJECT_NAME(id)
FROM syscomments
WHERE [text] LIKE '%whatever%'
The SSMS Tools Pack gives you this kind of search functionality plus various other cool things for free. And no, I don't work for them!
I have got one great tool that can find data anywhere located in the database. It is known as SQL Locator. Just Google it, that should be easy to find. Plus it is a freeware to download.
Thanks!
Related
This question already has answers here:
How to generate entire DDL of an Oracle schema (scriptable)?
(7 answers)
Closed 2 years ago.
I want to create tables from one schema to another. i.e. complete table script.
eg: Let say in schema 'A' tables are present and need to create in schema 'B'.
Can we do this with a scripts as there are lot of tables? or manually is the only option?
Could anyone pls suggests.
Thanks.
Yes it can be done by a script. Below, you will find the example of how to retrieve the DLL of a single Table. Now, using this example, you can create the script in no time.
SELECT DBMS_METADATA.get_ddl ('TABLE', table_name, owner)
FROM all_tables
WHERE owner = 'OWNER'
AND table_name = 'TABLE_NAME';
If you want the script directly, the following Link will provide you with your desired result:
How to generate entire DDL of an Oracle schema (scriptable)?
This question already has answers here:
Search for a string in all tables, rows and columns of a DB
(15 answers)
Closed 9 years ago.
I've been scouring online for an example of how to do this but haven't found anything at all. All the queries I've found assume you know what table you want to search.
I'm looking for a SQL query to simply search the ENTIRE database for a specific word.
There has to be such a thing right?
This is for MS SQL 2005/2008
Thanks
What do you mean by "entire database"? You need to find your values in tables only, or in object definitions, too?
I assume the former. In this case, you don't have to really know the structure of your DB. Try those views below. With them, you can construct your select queries on all the tables / colums. Just filter out non-*char columns, views and system tables, and you're ready to go - you can "automatically" generate multiple select statements.
select top 100 * from information_schema.tables
select top 100 * from information_schema.columns
The other option, is to use some addon to SSMS, like this one:
http://www.ssmstoolspack.com/
It has an option to search entire database.
But be advised, that both solutions will have a great impact on performance of your server.
This question already has answers here:
How to find stored procedures by name?
(4 answers)
Closed 8 years ago.
I have a large number of stored procedures in my database, and I would like to see if one of those would accomplish my task before I write a new one. How would I search through just the names of the existing stored procedures (as opposed to the contents)?
SQL Server 2005+:
SELECT name FROM sys.procedures WHERE name LIKE '%search_text%';
SQL Server 2000:
SELECT name FROM sysobjects WHERE name LIKE '%search_text%' AND xtype = 'P';
Another good idea is to establish a sensible naming schema. You shouldn't have to search at all if your naming convention is consistent and logical.
SELECT DISTINCT OBJECT_NAME(id)
FROM syscomments
WHERE OBJECT_NAME(id)
LIKE '%search_text%'
SELECT name
FROM sys.objects
WHERE type = 'P'
AND name LIKE '%search_text%'
The above methods all work great but an easier approach is to download a copy of SQL Search from Red Gate. It's a free utility that plugs into SSMS and allows you to search on all objects throughout the entire server.
This question already has answers here:
Different ways to alias a column
(3 answers)
Closed 8 years ago.
SELECT a=1,b=2
vs
SELECT 1 AS a, 2 AS b
what approach should i use ? (by best practice decisions)
Is there any advantages of one vs the other ?
Personally I use AS - it is more explicit and used elsewhere (table aliases).
It is also standard - using the = syntax will not work on some databases.
I don't believe there are any performance implications for using one over the other.
I dont think where is a difference. But i would prefer the second approach. I think its more logical than the first.
So, i use the AS approach.
AS temporarily assigns a table column a new name. This grants the SQL developer the ability to make adjustments to the presentation of query results and allow the developer to label results more accurately without permanently renaming table columns. Source
I use AS. It's a more SQL friendly way!
SELECT 1 AS a, 2 AS b
is common for all DBs
I am in the process of optimising my database and I was thinking of changing the datatype for some columns from DATETIME to SMALLDATETIME on my tables.
Is there a system stored procedure that returns both the contents/code of a store procedure and the dependent table which will then allow me to do a join on a filtered list of tables?
Cheers!
EDIT1:
Im looking to programatically rename the stored procedures not track dependencies!
The built-in dependency tracking for SQL isn't very good for this type of work. Two tools come to mind thought...
Red Gate SQL Dependency Tracker - Good for determining all the dependent code
Visual Studio for Database Developers - Contains TSQL Code Analysis which can identify if a piece of data is being treated as an incorrect type.
Red Gate has a free trial on their stuff, which might get you through this job
I answered a simliar question to this (link below) with a sample of a scipt I use to find text in stored procedures (and functions and views). It requires a bit of work, but might help you here.
[How to find data table column reference in stored procedures
[1]: http://How to find data table column reference in stored procedures
If your dependencies in SQL Server are accurate, you can use sys.sql_dependencies with appropriate joins.