Solved

General SQL-question!

Posted on 1997-08-18
2
175 Views
Last Modified: 2010-04-06
Hi!

I'm building a relational database (Paradox-tables) with about 15 tables that are related to eachother. When I delete a certain product that belongs to a certain customer I want to delete all records in about 10 tables with the following condition:

if (CustomerNumber = '???') AND (ProductNumber = '???') then
  delete the record


I've managed to use the TQuery object to delete the correct records from one table, the problem is how to do it from many tables, preferrably with one single SQL-question.
   The fields "CustomerNumber" and "ProductNumber" are of course present in all the tables.

   How do I solve this? Could you give me an example of what properties I need to set and the exact formulation of the SQL-query, I would be very grateful.

Daniel Persson, Sweden
0
Comment
Question by:Dippen
2 Comments
 
LVL 8

Expert Comment

by:ZifNab
ID: 1341789
Don't know much about SQL, but I would just iterate through all the tables and fire that SQL-query on them.

But maybe this can help. OOPSOFT gives at this moment their SQL editor SQL Express away for free! It's the full version! Though you have to be quick because they offer this only for a limited time. Just look at their site and I hope you'll find your answer there.


0
 
LVL 1

Accepted Solution

by:
Zonnald earned 150 total points
ID: 1341790
If the query is about the same for all tables why not use a string variable to name the table in the 'FROM' clause this way the same query can be used.

Alternatively you can pass the table name in hetrogenious query using the :TABLENAME notation.  Where TABLENAME CONTAINS the string for the table and the : means that this is a parameter assigned to the query component.  
Follow is the help out of DELPHI (3) which discusses the parameters and hetrogenious queries (not important that example is oracle)

Delphi supports heterogeneous queries, queries made against tables in more than one database. A heterogeneous query may join tables on different servers, and even different types of servers. For example, a heterogeneous query might involve a table in a Oracle database, a table in a Sybase database, and a local dBASE table. When you execute a heterogeneous query, the BDE parses and processes the query using Local SQL, so extended, server-specific SQL syntax is not supported.

To perform a heterogeneous query:

1.      Define a BDE standard alias that references a local directory, and set the DatabaseName property of the query component to that alias. To define BDE aliases use the Database Explorer.
2.      Define separate BDE aliases for each database accessed in the query.
3.      Specify the SQL statement to execute in the SQL property. Precede each table name in the SQL statement with the BDE alias for the database where that table can be found.
4.      Set any parameters for the query in the Params property.

5.      Call Prepare to prepare the query for execution prior to executing it for the first time.
6.      Call Open or ExecSQL depending on the type of query to execute.

For example, suppose you define an alias called Oracle1 for an Oracle database that has a CUSTOMER table, and Sybase1 for a Sybase database that has an ORDERS table. A simple query against these two tables would be:

SELECT CUSTOMER.CUSTNO, ORDERS.ORDERNO
FROM ":Oracle1:CUSTOMER", ":Sybase1:ORDERS"
WHERE CUSTNO = 1503
Contains the parameters for a query’s SQL statement.

property Params[Index: Word]TParams;

Description

Access Params at runtime to view and set parameter names, values, and data types dynamically (at design time use the Query Parameters editor to set parameter information). Params is a zero-based array of parameter records. Index specifies the array element to access.

Note

An easier way to set and retrieve parameter values when the name of each parameter is known is to call ParamByName. ParamByName cannot, however, be used to change a parameter’s data type or name.
Parameters used in SELECT statements cannot be NULL, but they can be NULL for UPDATE and INSERT statements.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

813 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

14 Experts available now in Live!

Get 1:1 Help Now