-
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
-
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
>
>
-
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
-
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
>
>
>
-
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
-
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
>
>
>
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
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
|
Bookmarks