• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 184
  • Last Modified:

General SQL-question!

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
Dippen
Asked:
Dippen
1 Solution
 
ZifNabCommented:
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
 
ZonnaldCommented:
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now