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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Drop/Truncate tables based on a stored procedures value 1

Status
Not open for further replies.

BobThornton

Programmer
Sep 12, 2022
12
US
I have the following so far -
USE MASTER
CREATE TABLE #TEMP_PHARM (
FILE_EXISTS INT
,FILE_DIRECTORY INT
,PARENT_DIRECTORY INT
)

INSERT INTO #TEMP_PHARM
EXEC xp_fileexist 'file path \ filename'

SELECT * FROM #TEMP_PHARM

Now I want to start DROP OR TRUNCATING tables (from a different database then the MASTER) where the value of FILE_EXISTS = 1 from the #TEMP_PHARM table

Any and all help is appreciated!!!
 
So, your code will create a table (with some sample data, I guess here):

[pre]
#TEMP_PHARM
FILE_EXISTS FILE_DIRECTORY PARENT_DIRECTORY
1 234 123
1 456 876
0 654 667[/pre]

What tables do you want to DROP or TRUNCATE based on the data in #TEMP_PHARM table?

Or am I getting this picture wrong [ponder]

---- Andy

"Hmm...they have the internet on computers now"--Homer Simpson
 
Hi Andy,

I want to drop/truncate tables in a different database
i.e. - DROP TABLE [database].[schema].RDTFOO
 
How do you know which tables to DROP?
It doesn't look (to me) your #TEMP_PHARM table holds any table names....

---- Andy

"Hmm...they have the internet on computers now"--Homer Simpson
 
It's part of an overall SQL query.
If the file is present -
1. drop tables
2. update table with new file
3. Do some table/field cleanup
 
I see we will not communicate since you refuse to answer any of my questions. Too bad. :-(

But, as a side note: CREATE TABLE ‘on-the-fly’, DROP TABLE ‘on-the-fly’, TRUNCATE TABLE ‘on-the-fly’ is possible, but why? That’s not the ‘regular’ approach to deal with the data in the DB (as far as I know). Why not just create a ‘permanent’ table once, set the fields needed, and then INSERT (instead of CREATE) records when needed, and UPDATE and/or DELETE records (instead of DROP or TRUNCATE temp tables) when needed.

There are uses/needs for temp tables in the DB, but for 99% of cases there are better solutions in well designed, normalized, relational data base.


---- Andy

"Hmm...they have the internet on computers now"--Homer Simpson
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top