SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


The Identity Select


The Identity Select

Author
Message
Steve Jones
Steve Jones
SSC Guru
SSC Guru (628K reputation)SSC Guru (628K reputation)SSC Guru (628K reputation)SSC Guru (628K reputation)SSC Guru (628K reputation)SSC Guru (628K reputation)SSC Guru (628K reputation)SSC Guru (628K reputation)

Group: Administrators
Points: 628503 Visits: 21336
Comments posted to this topic are about the item The Identity Select

Follow me on Twitter: @way0utwest
Forum Etiquette: How to post data/code on a forum to get the best help
My Blog: www.voiceofthedba.com
Stewart "Arturius" Campbell
Stewart "Arturius" Campbell
SSC Guru
SSC Guru (64K reputation)SSC Guru (64K reputation)SSC Guru (64K reputation)SSC Guru (64K reputation)SSC Guru (64K reputation)SSC Guru (64K reputation)SSC Guru (64K reputation)SSC Guru (64K reputation)

Group: General Forum Members
Points: 64659 Visits: 8234
Nice one to end the week on, thanks Steve

____________________________________________
Space, the final frontier? not any more...
All limits henceforth are self-imposed.
“libera tute vulgaris ex”
morlindk
morlindk
SSCrazy
SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)

Group: General Forum Members
Points: 2084 Visits: 579
Elegant!
- Yet, if I only wanted to add an identity column, in order to keep the table name (and save on storage), I would use simply
ALTER TABLE dbo.Names
ADD id INT IDENTITY(1, 1)
Shayn Thomas
Shayn Thomas
SSCarpal Tunnel
SSCarpal Tunnel (4.6K reputation)SSCarpal Tunnel (4.6K reputation)SSCarpal Tunnel (4.6K reputation)SSCarpal Tunnel (4.6K reputation)SSCarpal Tunnel (4.6K reputation)SSCarpal Tunnel (4.6K reputation)SSCarpal Tunnel (4.6K reputation)SSCarpal Tunnel (4.6K reputation)

Group: General Forum Members
Points: 4592 Visits: 863
thought it would error so tested and was pleasantly surprised,
will have to remember this one for future
thanks Steve

---------------------------------------------------------------------------------------
The more you know, the more you know that you dont know
Budd
Budd
SSCrazy
SSCrazy (3K reputation)SSCrazy (3K reputation)SSCrazy (3K reputation)SSCrazy (3K reputation)SSCrazy (3K reputation)SSCrazy (3K reputation)SSCrazy (3K reputation)SSCrazy (3K reputation)

Group: General Forum Members
Points: 2956 Visits: 915
Very interesting, but again it gets me thinking - I hate when that happens.... Smile
What is the difference between these 2 variations of today's QOD and how would you change the first one to make it as good at the second. Of course I'm talking about field length.
SELECT IDENTITY(INT, 1,1) AS id,bt.FirstName
INTO CustomerNames
FROM (SELECT * FROM (VALUES ('Steve'), ('Andy'), ('Brian')) AS Names(FirstName)) AS bt
---------------
CREATE TABLE Names
(firstname VARCHAR(100));
GO
INSERT dbo.Names (FirstName) VALUES ('Steve'), ('Andy'), ('Brian');
GO
SELECT IDENTITY(INT, 1,1) AS id,bt.FirstName
INTO CustomerNames
FROM Names AS bt

The only thing I noticed was varchar(5) as opposed to varchar(100).
Steve Jones
Steve Jones
SSC Guru
SSC Guru (628K reputation)SSC Guru (628K reputation)SSC Guru (628K reputation)SSC Guru (628K reputation)SSC Guru (628K reputation)SSC Guru (628K reputation)SSC Guru (628K reputation)SSC Guru (628K reputation)

Group: Administrators
Points: 628503 Visits: 21336
From the identity perspective, I don't think anything. either SELECT INTO is what it does. If you use it from different sources, you might get different results.

Follow me on Twitter: @way0utwest
Forum Etiquette: How to post data/code on a forum to get the best help
My Blog: www.voiceofthedba.com
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum









































































































































































SQLServerCentral


Search