Using sys.objects master table we can get the names of tables,views,stored procedures and all other objects in sql server database.
Here is the query.
select name from sys.objects where type='U' order by name
It will displays list of tables in the one Database.
Also you can use built in functionality that SQL Server provides and use one line of code to get all tables in all databases on database server.
sp_msforeachdb "SELECT '?' DatabaseName, Name FROM ?.sys.Tables
or use this query to find tables similar to the given name.
sp_msforeachdb "SELECT '?' DatabaseName, Name FROM ?.sys.Tables WHERE Name LIKE '%agent%'"
this query will return all tables those names contains "agent" with their Database name.
this query will returned result set , contain all dependencies, like which other tables, views, stored procedure depend on this table
Exec sp_depends 'table_name'
Here is the query.
select name from sys.objects where type='U' order by name
It will displays list of tables in the one Database.
Also you can use built in functionality that SQL Server provides and use one line of code to get all tables in all databases on database server.
sp_msforeachdb "SELECT '?' DatabaseName, Name FROM ?.sys.Tables
or use this query to find tables similar to the given name.
sp_msforeachdb "SELECT '?' DatabaseName, Name FROM ?.sys.Tables WHERE Name LIKE '%agent%'"
this query will return all tables those names contains "agent" with their Database name.
this query will returned result set , contain all dependencies, like which other tables, views, stored procedure depend on this table
Exec sp_depends 'table_name'
Comments
Post a Comment