Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / SQL Server / ADP / November 2004

Tip: Looking for answers? Try searching our database.

Deleting Records

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Aleks - 26 Nov 2004 19:00 GMT
Hi,

I need to delete records from my database, I have 3 tables

Table 1 has:

Users
1> UserId
2> CaseId

Here I have no problem, because I am deleting the user, so I use Delete from
table1 where userid = 1, that will delete the user from the table, the
problem is in table # 2

Cases
1> Id
2> CaseId

Here I don't have the UserId, but I have the CaseId, which comes from table
1 and can be linked.

How can I delete all 'cases' in table 2 where cases.caseid = users.caseid in
table 1 and users.userid in table 1 = 1 ?

In other words how can I delete all cases from table 2 where user = 1 ?

Thanks in advance,

Aleks
Norman Yuan - 27 Nov 2004 17:27 GMT
You are talking SQL Server/MDSE, aren't you?

Two ways, at least.

1. Turn on "Cascade delete related records" when create relationship bewteen
the two tables (when you establish relationship between tables in ADP
project's dialgram, a dialog box shows, allowing you to check a checkbox for
this; or in the diagram, you can right-click an existing relationship and
select properties, then select "Relationships" tab).

2. run multiple deleting: delete records in child table first, then the
record(s) in parent table:

DELETE FROM tblCases WHERE CaseID IN (SELECT CaseID FROM tblUsers WHERE
UserID=1)
DELETE FROM tblUsers WHERE UserID=1

You may want to wrap the multiple deleting statement in a transaction
(either in your application or in SQL Server), in case the parenet record
deleting fails, you can get deleted child records back.

> Hi,
>
[quoted text clipped - 25 lines]
>
> Aleks
Aleks - 28 Nov 2004 04:08 GMT
thx, ill try the second one using a stored procedure.

Aleks

> You are talking SQL Server/MDSE, aren't you?
>
[quoted text clipped - 51 lines]
>>
>> Aleks
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.