Solved

Idenitfy list of tables that not undergo any insert or delete operation?

Posted on 2013-05-15
6
224 Views
Last Modified: 2013-05-22
Is there any easy regex search way to identify whether no INSERT or DELETE happens in particular table?

The insert statement could be INSERT INTO tablename or INSERT tablename. The space could be more between the words. The same could be applied for DELETE.

How to search tables in a database that are not undergo insert or delete operation in all SPs, UDFs,..?

Please do assist.
0
Comment
Question by:Easwaran Paramasivam
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 6

Expert Comment

by:BurundiLapp
ID: 39167378
Depends on how many Stored Procedures or Functions you have.

It depends what your outcomes are but I would monitor the tables using a trigger to see which are ones have INSERT or DELETE run against them and then store that information into a seperate table.  Downside is it would take time to accumulate the data.

I would first create a table to store the tablename and last modification date.
CREATE TABLE [dbo].[Table_Monitor](
	[TableName] [nchar](80) NULL,
	[LastActiondate] [datetime] NULL
) ON [PRIMARY]

GO

Open in new window


And then place a trigger on all the other tables I wanted to monitor:

CREATE  TRIGGER [dbo].[DBTableMonitor1] 
ON [dbo].[Table_Monitor]
FOR INSERT, DELETE
AS
BEGIN
	DECLARE	@Date		DateTime,
			@Table 		NCHAR(80)

	SET @Table = 'Put Table Name Here'
	SET @Date = (SELECT GetDate())

	IF NOT Exists (SELECT * FROM Table_Monitor WHERE TableName = @Table)
		INSERT INTO Table_Monitor (TableName, LastActionDate) VALUES (@Table,@Date)
	ELSE
		UPDATE Table_Monitor SET LastActionDate = @Date WHERE TableName = @Table
	
END
GO

Open in new window


The Trigger name would need incrementing each time as trigger names have to be unique and the table name would need inputting to reference the table the trigger is on.

This would build up the Table_monitor table with all the info about the tables with that trigger on them on your system that have an INSERT or a DELETE run on them.
0
 
LVL 16

Author Comment

by:Easwaran Paramasivam
ID: 39167487
If I go for trigger operation, then I need to perform each and every transaction to insert or delete records in the tables. Moreover the number of tables are more.

Hence please do suggest solution to achieve with existing tables and database without creating trigger.
0
 
LVL 6

Accepted Solution

by:
BurundiLapp earned 500 total points
ID: 39167527
ok, if you add this Sp to your database you can then reference it to search within stored procedures.  It may require multiple searches to determine exactly what you are after though.

CREATE PROCEDURE FindTextInSP
@StringToSearch varchar(100) 
AS 
   SET @StringToSearch = '%' +@StringToSearch + '%'
   SELECT Distinct SO.Name
   FROM sysobjects SO (NOLOCK)
   INNER JOIN syscomments SC (NOLOCK) on SO.Id = SC.ID
   AND SO.Type = 'P'
   AND SC.Text LIKE @stringtosearch
   ORDER BY SO.Name
GO

Open in new window


Then run it like this:

exec FindTextInSP 'insert%into'

Open in new window


You can use % to indicate multiple characters or ? to indicate a single character.

The code came from here: http://stackoverflow.com/questions/2283826/how-can-i-programmatically-determine-if-a-stored-procedure-selects-from-another
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 16

Author Comment

by:Easwaran Paramasivam
ID: 39167556
That should be run for each and every table. Isn't it?

I've numerous tables in my database. Is there any other easy way to do it faster?
0
 
LVL 6

Expert Comment

by:BurundiLapp
ID: 39167568
No it should parse all the stored procedures in the database that the procedure is created in.
0
 
LVL 16

Author Closing Comment

by:Easwaran Paramasivam
ID: 39187342
Thanks.
0

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question