473,325 Members | 2,860 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,325 software developers and data experts.

updating and deleting parent and child table simultaneously

I have two table both say A and B.
If i insert a record in A that record should be inserted in B.
If i delete a record in A that record should be deleted from B.

Is that possible.If yes please tell me.

Thankyou in advance,
vishnu
Jul 20 '05 #1
3 3432
Hi

Without table structures (DDL - create table statements etc.. ) it is hard
to know exactly what you require. If the tables are different then usually
the records are inserted separately within a transaction, often using a
stored procedure. The deletions are usually taken care of by defining a
foreign key relationship between the child (referencing) table and the
parent (referenced) table. More information about these can be found in
books online.

John


"vishnu mahendra" <vi*************@yahoo.com> wrote in message
news:c2*************************@posting.google.co m...
I have two table both say A and B.
If i insert a record in A that record should be inserted in B.
If i delete a record in A that record should be deleted from B.

Is that possible.If yes please tell me.

Thankyou in advance,
vishnu

Jul 20 '05 #2
vishnu mahendra (vi*************@yahoo.com) writes:
I have two table both say A and B.
If i insert a record in A that record should be inserted in B.
If i delete a record in A that record should be deleted from B.

Is that possible.If yes please tell me.


Yes, this is possible. For the insertion part, you would need to
have a trigger:

CREATE TRIGGER replicate_tri ON A FOR INSERT AS
INSERT B (...)
SELECT ...
FROM inserted
go

For the deletion part, you could have another trigger, but you could
also set up a cascading foreign-key constraint as John suggested.

--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 20 '05 #3
>> If I insert a record [sic] in A that record [sic] should be inserted
in B. If I delete a record [sic] in A that record [sic] should be
deleted from B. <<

If you have two identical tables in the same schema, you have a
redundancy and need to get rid of one of them.

If this was a file system -- where they DO have records and not rows
(HUGE difference)!! -- then you might expect this sort of design.

Back in the 1950's we would often take one tape and make mulitple copies
of the data, sometimes in a different order, so we could run several
reports at the same time. Is this what you are doing?

--CELKO--
===========================
Please post DDL, so that people do not have to guess what the keys,
constraints, Declarative Referential Integrity, datatypes, etc. in your
schema are.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #4

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

Similar topics

1
by: KC | last post by:
Hello, I am using Access 2002. WinXP, Template from MS called Orders Mgmt DB. I have tweaked this DB to work for our small co. It has worked pretty well up until I made the mistake of deleting...
2
by: Kenny | last post by:
Hello all, I've made a dataset by using the xsd tool in C#. In the xsd schema, there are a few tables, each has its own primary key. And, I've made relation between them. After all things are...
5
by: Patrick Vanden Driessche | last post by:
Hi All, I'm currently writing an in-house Form validation framework (WinForms) which is based on 'Component'-inheriting object. So basically, I have a small hierarchy. FormValidator +--...
10
by: jaYPee | last post by:
does anyone experienced slowness when updating a dataset using AcceptChanges? when calling this code it takes many seconds to update the database SqlDataAdapter1.Update(DsStudentCourse1)...
14
by: Lars Netzel | last post by:
A little background: I use three Datagrids that are in a child parent relation. I Use Negative Autoincrement on the the DataTables and that's workning nice. My problem is when I Update these...
7
by: Susan Mackay | last post by:
I have a data table that is connected to a database table with a data adapter in the 'standard' manner. However I want to be able to remove selected rows from the data table (i.e. no longer...
0
by: kolalakitty | last post by:
Hopefully someone here can help me/point me in the right direction. I've found tons of references towards making relations, creating rows, saving said rows, using datagrids, databinding objects,...
3
by: querry | last post by:
Hi there, I have a problem. I am devloping a C# ASP.NET User Control (a .ascx file). I want to display a table on the user control. This table is generated on the fly. First the...
0
by: romcab | last post by:
Hello expert, I would like to ask how can I add a parent node and child node simultaneously. I try this code; //create parent node XmlElement ^elem =...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.