Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

No PK's, No FK's, No Indexes, No Service!

Status
Not open for further replies.

pulsar6

Programmer
Sep 16, 2003
3
US
I'm trying to delete old records from a database that has only four tables. Only one table has a "timestamp" column, the others do not. This is not a relational database at all; No primary keys, no foreign keys and the indexes are the same on all of the tables.
This database has violated every rule of relational database construction there is.

Now the tables are full of old data and the "database owner" has requested me to delete old data from them.Could you tell me how do you delete data from four tables that work together but do not relate to each other?
I have suggested adding a "date column" with a getdate()so it will be a lot easier to delete "same records".
Any ideas?

Your prompt answer will be appreciated.
 
If you can't join them and they have no relationship... and only one has a timestamp how are you going to be able to tell what is old or not on the other tables?

In other words, maybe some examples of our tables could help us spawn some ideas :)

You might create a temp table for each table that makes an ad-hoc join PK ID then join all the temp tables to get the timestamp to know what to whack..... just an idea without know what the tables look like.
 
twifosp;
Your observation is exactly what I've been saying to the database owner. She says that by writing a subquery you can achieve it. I still say no way!.
 
pulsar6,

You state that the tables 'work together but do not relate to each other', how do they achieve this? What type of application drives this database? is there any coding in the Application that makes these apparent joins?

As twifosp correctly points out, what denotes 'old data' in the tables that have no timestamp (and what denotes 'old data' in the one that does!)?

Was it the 'database owner' that designed this database? If so, then she would be in a position to answer these questions, if not, then maybe you could lend her a book on RDBMS design concepts and ask her to look up the 'subquery' she appears to have such faith in.

As alast resort, before you admit failure to the DB owner, post the schemas with some sample data and maybe someone here can come up with some ideas. I'd give it a try, anyway.

Logicalman

 
pulsar6,

I think I would add an integer field, with a auto-incrementing number on it. As in
[testfield] [int] IDENTITY (1, 1) NOT NULL

and use this as a primary key on all 4 tables.

Deletions are a lot easier when you can select out a single record.

Regards
Henrik
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top