Drop/Truncate tables based on a stored procedures value
Drop/Truncate tables based on a stored procedures value
(OP)
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!!!
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!!!
RE: Drop/Truncate tables based on a stored procedures value
What tables do you want to DROP or TRUNCATE based on the data in #TEMP_PHARM table?
Or am I getting this picture wrong
---- Andy
"Hmm...they have the internet on computers now"--Homer Simpson
RE: Drop/Truncate tables based on a stored procedures value
I want to drop/truncate tables in a different database
i.e. - DROP TABLE [database].[schema].RDTFOO
RE: Drop/Truncate tables based on a stored procedures value
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
RE: Drop/Truncate tables based on a stored procedures value
If the file is present -
1. drop tables
2. update table with new file
3. Do some table/field cleanup
RE: Drop/Truncate tables based on a stored procedures value
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
RE: Drop/Truncate tables based on a stored procedures value