473,320 Members | 1,691 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Empty a table before using DTS to append records?

In Access I have a macro that, each night, takes a table with a
primary key defined in it, and deletes all the rows. Then it
imports/appends records from a fixed width text file. In this way,
since the table is not deleted and recreated, the primary key is kept
intact.

What would be the equivalent SQL method for doing this in an automated
way? I've tried letting DTS import the table from Access, but the
primary key is lost. Is there some way to "empty" a table instead of
dropping it, and then append new records so that the table will end up
having the primary key I want it to have?

Thanks.

Larry
- - - - - - - - - - - - - - - - - -
"Forget it, Jake. It's Chinatown."
Jul 20 '05 #1
4 4683

"Larry Rekow" <larry@netgeexdotcom> wrote in message
news:2g********************************@4ax.com...
In Access I have a macro that, each night, takes a table with a
primary key defined in it, and deletes all the rows. Then it
imports/appends records from a fixed width text file. In this way,
since the table is not deleted and recreated, the primary key is kept
intact.

What would be the equivalent SQL method for doing this in an automated
way? I've tried letting DTS import the table from Access, but the
primary key is lost. Is there some way to "empty" a table instead of
dropping it, and then append new records so that the table will end up
having the primary key I want it to have?

Thanks.

Larry
- - - - - - - - - - - - - - - - - -
"Forget it, Jake. It's Chinatown."


I don't really understand what you mean, but I guess that your primary key
column is an IDENTITY column, and you want to remove all data in the table
without resetting the identity value back to 1 (or whatever your seed was)?
The simple way is just this:

delete from dbo.MyTable

This can be slow on large tables with many rows, which is why TRUNCATE TABLE
is often used instead, although it will reset the identity seed.

If this isn't helpful, or if I didn't understand correctly, then you should
post some more detailed information, in particular the CREATE TABLE
statement for your target table (including constraints), and what the data
looks like that you want to import. It would also be good to know if you
want MSSQL to generate new identity values for your primary key, or if you
already have values in the source data which you want to keep.

Simon
Jul 20 '05 #2
On Thu, 2 Sep 2004 19:43:18 +0200, "Simon Hayes" <sq*@hayes.ch> wrote:
If this isn't helpful, or if I didn't understand correctly, then you should
post some more detailed information, in particular the CREATE TABLE
statement for your target table (including constraints), and what the data
looks like that you want to import. It would also be good to know if you
want MSSQL to generate new identity values for your primary key, or if you
already have values in the source data which you want to keep.

Simon

++++++++++++++++++++++++++++++++++++++++++++++++++ ++++
Already have values in the source data, a unique field called
"FILE_NUM".

The default statement that DTS creates for me starts out with:

CREATE TABLE [hoyt].[dbo].[IMP7TEXT] (
[IMP_ID] nvarchar (12) NULL,
[CUST_ID] nvarchar (12) NULL,
[FILE_NUM] nvarchar (8) NULL,
etc......

Because I'm using this table in an ASP.Net website, I want to relate
it to other tables that also have the FILE_NUM values.

Would it be as simple as editing the CREATE TABLE statement to specify
that FILE_NUM is the primary key? (yes, i'm very new at MS SQL).

Thanks,

Larry

- - - - - - - - - - - - - - - - - -
"Forget it, Jake. It's Chinatown."
Jul 20 '05 #3
Larry Rekow (larry@netgeexdotcom) writes:
The default statement that DTS creates for me starts out with:

CREATE TABLE [hoyt].[dbo].[IMP7TEXT] (
[IMP_ID] nvarchar (12) NULL,
[CUST_ID] nvarchar (12) NULL,
[FILE_NUM] nvarchar (8) NULL,
etc......

Because I'm using this table in an ASP.Net website, I want to relate
it to other tables that also have the FILE_NUM values.

Would it be as simple as editing the CREATE TABLE statement to specify
that FILE_NUM is the primary key? (yes, i'm very new at MS SQL).


Not really. First you would have to make the column NOT NULL before you
can make it a primary key. Then you probably would have to set up foriegn-
key relations as well. Then again, that depends on what you mean with
relate. I don't know ASP .Net, but may you are really talking data tables
in ADO .Net?

--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 20 '05 #4
On Thu, 2 Sep 2004 22:00:18 +0000 (UTC), Erland Sommarskog
<es****@sommarskog.se> wrote:
Larry Rekow (larry@netgeexdotcom) writes:
The default statement that DTS creates for me starts out with:

CREATE TABLE [hoyt].[dbo].[IMP7TEXT] (
[IMP_ID] nvarchar (12) NULL,
[CUST_ID] nvarchar (12) NULL,
[FILE_NUM] nvarchar (8) NULL,
etc......

Because I'm using this table in an ASP.Net website, I want to relate
it to other tables that also have the FILE_NUM values.

Would it be as simple as editing the CREATE TABLE statement to specify
that FILE_NUM is the primary key? (yes, i'm very new at MS SQL).


Not really. First you would have to make the column NOT NULL before you
can make it a primary key. Then you probably would have to set up foriegn-
key relations as well. Then again, that depends on what you mean with
relate. I don't know ASP .Net, but may you are really talking data tables
in ADO .Net?

++++++++++++++++++++++++++++++++++++++++++++++++++ ++++
Thanks to you and Simon for responses and hints. Yes, after more
googling, reading, discovering, I made FILE_NUM NOT NULL and was able
to make it the primary key by editing the MAKE TABLE query DTS put
together; now looking into defining the foreign keys, etc.

The penny is starting to drop :)

Larry
- - - - - - - - - - - - - - - - - -
"Forget it, Jake. It's Chinatown."
Jul 20 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Scott Kinney | last post by:
I have an inventory database. I want to delete out-of-stock items from the main database, but keep them in a separate table so that I can reference data about them. I created a copy of the item...
3
by: Steve Housechild | last post by:
I have a table of 'Customers', a table of 'Newsletters' and a table for storing which customers have recieved which letters 'CustLett'. By using a query, I have pulled a list of customers who...
3
by: Larry Rekow | last post by:
As part of a macro, I'm trying to automate appending a table with new records. let's say the table 2 has some new records in it, but also has a lot of identical records to table 1. I would...
2
by: David | last post by:
Hi, I have an order form which has a field 'ProductID'. This form has a button on each record to open a new form linked by ProductID. This new form is a continuous form and obviously, only...
6
by: Sven Pran | last post by:
Probably the answer is there just in front of me only awaiting me to discover it, but: 1: I want to build a query that returns all records in one table for which there is no successful "join"...
5
by: Michael C via AccessMonster.com | last post by:
Hello, I have a table that I am appending 3 seperate tables into. My main problem is that each time I append the data, it simply adds to the data already there. That might sound ok, except that...
22
by: RayPower | last post by:
I'm having problem with using DAO recordset to append record into a table and subsequent code to update other tables in a transaction. The MDB is Access 2000 with the latest service pack of JET 4....
3
by: wvmbark | last post by:
First time poster... I just found this forum and it appears there's plenty of people here that could make short work of problem that's been driving me absolutely bonkers for months. Every day we...
4
by: Bob | last post by:
Hi all, I'm trying to import data, modify the data then insert it into a new table. The code below works fine for it but it takes a really long time for 15,000 odd records. Is there a way I...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.