AutoNumber/Counter @ Import

Posted on 2006-06-06
Last Modified: 2013-11-30
Hiya All,

I want to have an autonumber/counter column in a table that I import flat files into, I clear the table each time I do an import so I would like the number to start at one each time. I use DTS to import the flat file to the table.

How do I do this?

Question by:dehmerl

    Author Comment

    Guess What!

    I found it out myself!

    Make a new row in the table, data type is int and then use the identity options!
    LVL 13

    Accepted Solution

    You got it... except that it doesn't always restart the identity key at 1.

    Look into DBCC CHECKIDENT (tablename, RESEED, 1)
    LVL 14

    Expert Comment

    Turn on Identity on the autonumber culumn in the table.  before you start your process, simply execute

    truncate table <yourtable>

    thus will reset the autonumber and delete all the records that may be left in the table.

    Author Comment

    ahh thanks!

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Join & Write a Comment

    When you hear the word proxy, you may become apprehensive. This article will help you to understand Proxy and when it is useful. Let's talk Proxy for SQL Server. (Not in terms of Internet access.) Typically, you'll run into this type of problem w…
    JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
    Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
    Viewers will learn how the fundamental information of how to create a table.

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now