473,376 Members | 1,029 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,376 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 3435
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 =...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.