DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 6 of 6
  1. #1
    Colin McGuigan Guest

    Insert with no columns?

    SQL Server 7.0

    I have a table that has only one column, which is an identity field. It's
    used only for ensuring that a transaction has a unique number. My problem
    is I don't know how to INSERT a new record into it to get a new identity.
    I've tried all variants that I can think of of:

    INSERT TransactionCounter
    INSERT TransactionCounter()
    INSERT TransactionCounter VALUES
    INSERT TransactionCounter VALUES ()
    INSERT TransactionCounter() VALUES ()

    ....but nothing seems to work. I can easily jury rig around this by simply
    adding a dummy field and inserting a spurious value into that, but I'm
    curious: is there a syntax to do an insert without specifying any columns?

    --
    Colin McGuigan



  2. #2
    D. Patrick Hoerter Guest

    Re: Insert with no columns?

    Colin,

    No.

    As an aside, I like to use a single-column, single-row integer table for
    this purpose, doing like so:

    CREATE PROCEDURE GetNextID (@iNextID int OUTPUT) AS

    SET TRANSACTION ISOLATION LEVEL SERIALIZABLE

    UPDATE ID_Source SET ID_Value = ID_Value + 1

    SELECT @iNextID = ID_Value FROM ID_Source

    RETURN


    Your method of availing yourself of the services of the IDENTITY column
    works great, though.

    Regards,
    D. Patrick Hoerter

    Colin McGuigan wrote in message <3989ed31$1@news.devx.com>...
    >SQL Server 7.0
    >
    >I have a table that has only one column, which is an identity field. It's
    >used only for ensuring that a transaction has a unique number. My problem
    >is I don't know how to INSERT a new record into it to get a new identity.
    >I've tried all variants that I can think of of:
    >
    >INSERT TransactionCounter
    >INSERT TransactionCounter()
    >INSERT TransactionCounter VALUES
    >INSERT TransactionCounter VALUES ()
    >INSERT TransactionCounter() VALUES ()
    >
    >...but nothing seems to work. I can easily jury rig around this by simply
    >adding a dummy field and inserting a spurious value into that, but I'm
    >curious: is there a syntax to do an insert without specifying any columns?
    >
    >--
    >Colin McGuigan
    >
    >



  3. #3
    Colin McGuigan Guest

    Re: Insert with no columns?

    D. Patrick Hoerter wrote in message <398a1c92@news.devx.com>...
    >Colin,
    >
    > No.


    Ah. I found one, actually, which I post here to commit to the immortal
    memory of news.devx.com (long live news.devx.com!):

    INSERT TransactionCounter DEFAULT VALUES


    --
    Colin McGuigan




  4. #4
    D. Patrick Hoerter Guest

    Re: Insert with no columns?

    Colin,

    I'll be damned. In all this time I never saw that option. Was that
    possible on 6.5? I don't remember it.

    Regards,
    D. Patrick Hoerter

    Colin McGuigan wrote in message <398b0ac1$1@news.devx.com>...
    >D. Patrick Hoerter wrote in message <398a1c92@news.devx.com>...
    >>Colin,
    >>
    >> No.

    >
    >Ah. I found one, actually, which I post here to commit to the immortal
    >memory of news.devx.com (long live news.devx.com!):
    >
    >INSERT TransactionCounter DEFAULT VALUES
    >
    >
    >--
    >Colin McGuigan
    >
    >
    >



  5. #5
    Colin McGuigan Guest

    Re: Insert with no columns?

    D. Patrick Hoerter wrote in message <398b3e32@news.devx.com>...
    >Colin,
    >
    > I'll be damned. In all this time I never saw that option. Was that
    >possible on 6.5? I don't remember it.
    >
    >Regards,
    >D. Patrick Hoerter


    Yeah; it gets all of two lines in the help file. I don't know why I noticed
    it there, I just did. As for 6.5...I honestly haven't a clue. I
    uninstalled my last copy of 6.5 off of a computer here sometime around half
    a year ago...


    --
    Colin McGuigan




  6. #6
    D. Patrick Hoerter Guest

    Re: Insert with no columns?

    Colin,

    >. I
    >uninstalled my last copy of 6.5 off of a computer here sometime around half
    >a year ago...



    Lucky! So far, I've worked in 2 mixed environ.'s. Not complaining, it's
    just fun keeping track of which version you're coding against with stored
    procedures.... You can't do that! Yes, you can! Wait, no you can't. Wait...
    ;-)


    Colin McGuigan wrote in message <398ec10b@news.devx.com>...
    >D. Patrick Hoerter wrote in message <398b3e32@news.devx.com>...
    >>Colin,
    >>
    >> I'll be damned. In all this time I never saw that option. Was that
    >>possible on 6.5? I don't remember it.
    >>
    >>Regards,
    >>D. Patrick Hoerter

    >
    >Yeah; it gets all of two lines in the help file. I don't know why I

    noticed
    >it there, I just did. As for 6.5...I honestly haven't a clue. I
    >uninstalled my last copy of 6.5 off of a computer here sometime around half
    >a year ago...
    >
    >
    >--
    >Colin McGuigan
    >
    >
    >



Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links