Saturday, February 25, 2012

overwriting a database

I am very new to SQL and I hope I am in the right place for this question. I have a database (I believe it is just one table) that needs to be overwritten with an import of a text file every night. I know there is a very easy way to do it, I just don't have a clue what it might be.

The database is IPTVprogramsSQL and the table is programs. I am pretty sure the fields names are matched. Again, I am very new and have been thrown in way over my head.

Thanks for any help I can get.

What tools are you using? If you can execute SQL, just run:

TRUNCATE tablename

Or

DELETE tableName --if truncate won't work

to remove the data. Then just reload it however you are now.

|||if ur using DTS/ssis to do this..simply select the option to delete existing records...befor inserting from txt file.|||

first question - what tool will you use to import the data?

If you're on SQL2005 you should probably look at using SQL Server Integration Services (SSIS) to perform this if it's installed on your server. For SQL2000, you can do it with DTS pretty easily.

There should be an Import Data wizard in Enterprise Manager (or SQL Server Management Studio if you're on 05) that can help you get started. From SSMS, right click the DB you want to target and select Import Data from the Tasks sub-menu item.

Your question is a bit beyond the scope of this group - but hopefully this will get you started in the right direction.

If you want to overwrite the data, you can use the facility of the tool to specify this, or if you're doing it from a stored procedure or T-SQL batch, you can use the truncate table command to empty the table before you load it.

|||I would like to have this as a stored process that is executed by the server agent. I am using 2005 w/SP1. I tried to just import the data and save that procedure. I assume I would do the same thing with deleting or truncating command?|||

create procedure usp_truncate_tablename

as
truncate <table name>

go

Allen_Iowa wrote:

I would like to have this as a stored process that is executed by the server agent. I am using 2005 w/SP1. I tried to just import the data and save that procedure. I assume I would do the same thing with deleting or truncating command?

No comments:

Post a Comment