Solved

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

Posted on 2013-05-15
6
213 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
  • 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Long way back, we had to take help from third party tools in order to encrypt and decrypt data.  Gradually Microsoft understood the need for this feature and started to implement it by building functionality into SQL Server. Finally, with SQL 2008, …
In this article I will describe the Detach & Attach method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

707 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now