I am just starting a conversion from Access to SQL Server 2005 and I'm using it as an opportunity to learn SQL Server in the process.
I am testing extensively but want to occasionally update the SQL Server testing db with data from my live Access database.
I need to drop all tables from my database and then run my stored procs and SSIS package every time I update the data, which is fine, but I have a simple thing I need to do that I can't seem to figure out.
(Keep in mind I'm new to writing T-SQL!)
Here's the code I'm using to drop all the tables (and it's not working!)
Any suggestions for what I'm doing wrong?
Thanks for the help!
I am testing extensively but want to occasionally update the SQL Server testing db with data from my live Access database.
I need to drop all tables from my database and then run my stored procs and SSIS package every time I update the data, which is fine, but I have a simple thing I need to do that I can't seem to figure out.
(Keep in mind I'm new to writing T-SQL!)
Here's the code I'm using to drop all the tables (and it's not working!)
Code:
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Description: DROPS all the tables in the database--for use
-- during import of the GPTData Access database.
-- =============================================
ALTER PROCEDURE [dbo].[DropTables]
-- Add the parameters for the stored procedure here
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
DECLARE @TableName varchar(800);
DECLARE @strSQL varchar(8000);
DECLARE c1 CURSOR FOR
SELECT TABLE_NAME
FROM INFORMATION_SCHEMA.TABLES
FOR READ ONLY
OPEN c1
FETCH NEXT FROM c1
INTO @TableName
-- loop until we run out of rows
WHILE @@FETCH_STATUS = 0
BEGIN
IF LEFT (@TableName, 1) != 'V'
BEGIN
SET @strSQL = 'DROP TABLE ' + @TableName
EXECUTE (@strSQL)
END
FETCH NEXT FROM c1
INTO @TableName
END
CLOSE c1
DEALLOCATE c1
END
Any suggestions for what I'm doing wrong?
Thanks for the help!