I need to search SQL Server's metadata for all stored procedures that were changed between specific dates.
So far I have following query that looking for specific value in the SP.
SELECT DISTINCT sysobjects.name AS [Object Name]
FROM sysobjects,syscomments
WHERE sysobjects.id = syscomments.id
and syscomments.text like '%Stock%'
In the example above I am looking for all SP that have word Stock in it.
But how can I search for all SP's that were changed between specific dates?
USE AdventureWorks;
GO
SELECT name, create_date, modify_date
FROM sys.objects
WHERE type = 'P'
AND name = 'uspUpdateEmployeeHireInfo'
GO
source: http://blog.sqlauthority.com/2007/08/10/sql-server-2005-find-stored-procedure-create-date-and-modified-date/
Related
I have an application which stores all data in SQL Server 2008. This application creates, modifies, updates tables. The name of the database is XLPR_2001 and it contains nearly 500 tables.
I want to find out changes if I made through application where it affect the entire database (XLPR_2001). If I find it so I can directly made those changes directly in the database, I complete my work very fast.
I search it on web but not help me in my case.
As your Question, you are looking for Table Change Effect :
SELECT name [TableName],
Create_date [CreateDate],
modify_date [LastUpdate]
FROM sys.all_objects
WHERE type = 'U'
ORDER BY modify_date DESC;
From above SQL Command which would give you all Table_Name which are last effected by some activities (i.e. insert, update or delete).
Result :
#sarslash and #Yogesh in my case your code show very old result. I found below code on somewhere and it work perfectly.
select
object_name(object_id) as OBJ_NAME, *
from
sys.dm_db_index_usage_stats
where
database_id = db_id(db_name())
Order by
dm_db_index_usage_stats.last_user_update desc
You can find this info at modify_date column of sys.objects table
SELECT name, modify_date from sys.objects where type ='U' order by modify_date desc
I have created a database in SQL Server 2012 with name "yadav". Now I want to know where "Yadav" DB info is stored like Created Date, Number of Tables, User Name etc.
Thanks in advance.
Some basic things are accessible in the sys.databases catalog view:
SELECT name, database_id, create_date
FROM sys.databases
WHERE name = 'yadav'
For other, you'll have to go to your database:
USE yadav;
SELECT TableCount = COUNT(*)
FROM sys.tables
and there's a vast collection of other system catalog views which provide insight into your database and its objects
You need something like this
sp_helpdb 'Yadav'
You can get the database information from sys.databases table.
select *
from sys.databases
where name = database_name
and table information from INFORMATION_SCHEMA.COLUMNS table.
select *
from INFORMATION_SCHEMA.COLUMNS
where TABLE_CATALOG = database_name
Is there some SQL that will either return a list of table names or (to cut to the chase) that would return a boolean as to whether a tablename with a certain pattern exists?
Specifically, I need to know if there is a table in the database named INV[Bla] such as INVclay, INVcherri, INVkelvin, INVmorgan, INVgrandFunk, INVgobbledygook, INV2468WhoDoWeAppreciate, etc. (the INV part is what I'm looking for; the remainder of the table name could be almost anything).
IOW, can "wildcards" be used in a SQL statement, such as:
SELECT * tables
FROM database
WHERE tableName = 'INV*'
or how would this be accomplished?
This should get you there:
SELECT *
FROM INFORMATION_SCHEMA.TABLES
where table_name LIKE '%INV%'
EDIT:
fixed table_name
To check for exists:
--
-- note that the sql compiler knows that it just needs to check for existence, so this is a case where "select *" is just fine
if exists
(select *
from [sys].[tables]
where upper([name]) like N'INV%')
select N'do something appropriate because there is a table based on this pattern';
You can try the following:
SELECT name FROM sys.tables where name LIKE 'INV%';
I use SQL Server 2008 R2.
I have a table with 5 records. The table does not have any column that keeps track of LastUpdated or something like that.
Is it possible to find out when was the last date/time that someone added/changed a record? Which record was that?
Thanks.
In General Practice you should add column to do this ,But any ways you can see the last time the table was Modified
if you want to check the Structure Modiifcation
USE
SELECT * FROM SYS.Tables where Name Like '[TableName]'
Here Column Modify_Date will give you last time table was modified
if you want to check the Data Modiifcation
USE
SELECT OBJECT_NAME(OBJECT_ID) AS TableName, last_user_update
FROM sys.dm_db_index_usage_stats
WHERE database_id = DB_ID( '[YourDatabaseName]')
If you want to know the latest modification datetime on that table then use
Select modify_date from sys.tables where name = 'tablename'
If you want to know the particular record then there is no way you have to use :
Alter table tablename add modifieddate datetime
select t.name, user_seeks, user_scans, user_lookups, user_updates, last_user_seek, last_user_scan, last_user_lookup, last_user_update
from sys.dm_db_index_usage_stats i JOIN sys.tables t ON (t.object_id = i.object_id)
where database_id = db_id()
I want to fetch the tables and stored procedures added in last 5 or 6 months to a particular database.
I have tried using the below command but it is not giving correct data.
select * from sys.objects
where type = 'U' or type = 'P'
and modify_date between '2012-09-01' and '2013-01-29'
Please suggest which command can give me this list.
If you are looking for objects ADDED, then why are you querying on modify_date? Shouldn't you be looking at create_date?
select * from sys.objects
where (type = 'U' or type = 'P')
and create_date between '2012-09-01' and '2013-01-29'
Also, you have not put your OR in parentheses, which means that you will get incorrect results anyway.
Raj