473,396 Members | 2,068 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

question about cascading deletes

Dan
Hi, I'm using SQL server 2000, and I have set up two tables, table A
and table B. Table A and B have a foreign key constraint such that if
an entry is deleted in table A, then all the entries in table B
associated with that entry are deleted as well. I imagine that I can
find out the number of records that are deleted in table A when I
execute the SQL, but is there an easy way of determining the number of
records that will be deleted in table B?

Thanks,
Dan
Jul 20 '05 #1
1 1569

"Dan" <en********@sbcglobal.net> wrote in message
news:8c**************************@posting.google.c om...
Hi, I'm using SQL server 2000, and I have set up two tables, table A
and table B. Table A and B have a foreign key constraint such that if
an entry is deleted in table A, then all the entries in table B
associated with that entry are deleted as well. I imagine that I can
find out the number of records that are deleted in table A when I
execute the SQL, but is there an easy way of determining the number of
records that will be deleted in table B?

Thanks,
Dan


When you execute the delete statement, @@ROWCOUNT will have the number of
rows deleted from A, but there is no similar way to find out the rows
deleted from B. You could query how many rows will be affected by your
delete criteria before deleting, but that may not be reliable - if the
system is busy, the number of rows could change between your SELECT and your
DELETE queries.

One possible approach is a trigger on the child table (B) which stores
@@ROWCOUNT in a log table:

create trigger dbo.MyTrigger
on dbo.MyChildTable
after delete
as
declare @i int
set @i = @@ROWCOUNT
if @i > 0
insert into dbo.MyLogTable (TableName, RowsDeleted)
values ('MyChildTable', @i)

Simon
Jul 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
by: Dan Williams | last post by:
I am using Microsoft SQL Server 2000 and have a question about our database design. Here is a sublist of tables and columns we currently have:- Employee ---------- Ee_Code PRIMARY KEY...
5
by: Mike Wiseley | last post by:
I would like to create a delete query that consists of two tables linked together. One table will be the target for the deletions while the other table's equi-joins will tell the delete query which...
2
by: deko | last post by:
This may be an easy question, but for some reason the multiple table design idea is throwing me. I'm trying to avoid using one large, wide table - so I've got multiple tables that hold different...
8
by: Glenn Lerner | last post by:
When I used Visual Studio 6 I was able to cascade source code windows. This allowed me to view 2 separate source code files side by side and copy and paste between windows. How do I do this in...
5
by: Jason MacKenzie | last post by:
Just curious about some suggested approaches to this issue (which must be common). A user goes to a page to create a new project. We have a requirement that they must see the project number...
8
by: penguin732901 | last post by:
A database keeps track of invoices (date, amount, balance, category, etc) and advertisements (size, text, sponsored by, date entered etc) (among other things). Sometimes, an advertisement is...
1
by: cesar.guinovart | last post by:
I have the following table CREATE TABLE ( int IDENTITY(1,1) CONSTRAINT PK_tbl_Items__item_id PRIMARY KEY, int DEFAULT(NULL) CONSTRAINT FK_tbl_Items__item_id__parent_id REFERENCES ( ...
18
by: john | last post by:
I have 3 tables: Message, Workgroup, and Hyperlink. Message has 1xM link with Hyperlink and Workgroup has 1xM link with Hyperlink. Hyperlink has the following fields: IDhyperlink* IDmessage...
0
by: brockuswade | last post by:
I have an opinion question relating to deleting important records in a human resources database. Any "best practices" papers or "white papers" anyone know of would help tremendously. Here is the...
1
by: CoreyReynolds | last post by:
Hello, I have attached a picture of my Access form. Each record has a delete button beside it, pressing it deletes the record and cascades to the child records. Horray. Except sometimes, for a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.