dbTalk Databases Forums  

SQL Express - Identity specification property - how to change

comp.databases.ms-sqlserver comp.databases.ms-sqlserver


Discuss SQL Express - Identity specification property - how to change in the comp.databases.ms-sqlserver forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Mike
 
Posts: n/a

Default SQL Express - Identity specification property - how to change - 11-23-2007 , 01:55 AM






Hi, I use SQL Server Enterprise Manager for MS SQL Express and i want
to change the column properites for [int]
type of column, but I cann't change it.

More in details...
I'd like to set autoincremntal option and in order to change that I am
trying to change Identity specification from no to yes, without
success.
It is primary key too,
Name AricleID,
int type,
Primary set of binding --> ((0))
Full text specification --> No
Identity specification --> No --> I want to change this

Everything else is disabled

Thanks

Reply With Quote
  #2  
Old   
Erland Sommarskog
 
Posts: n/a

Default Re: SQL Express - Identity specification property - how to change - 11-23-2007 , 04:29 PM






Mike (ablyplus (AT) yahoo (DOT) com) writes:
Quote:
Hi, I use SQL Server Enterprise Manager for MS SQL Express and i want
to change the column properites for [int]
type of column, but I cann't change it.

More in details...
I'd like to set autoincremntal option and in order to change that I am
trying to change Identity specification from no to yes, without
success.
It is primary key too,
Name AricleID,
int type,
Primary set of binding --> ((0))
Full text specification --> No
Identity specification --> No --> I want to change this
First of all, why do you want to use IDENTITY? IDENTITY is primarily
of interest when you have many simultaneous insert operations. In that
case, rolling your own with SELECT MAX causes serialization and poor
throughput.

But if you don't have a high-concurrency scenario, there is little reason
to use IDENTITY. It's likely to cause your more trouble than benefit in
the long run. Rolling your own is very simple:

BEGIN TRANSACTION

SELECT @id = coalesce(MAX(id), 0) + 1 FROM tbl WITH (UPDLOCK)

INSERT (id, ,...)
VALUES (@id, ....)

COMMIT TRANSACTION

One of the many problems with IDENTITY is the one you are facing now:
there is no ALTER TABLE syntax for adding the IDENTITY property to a
column, but you need to create a new table and copy data over, and in
that process, make sure that you include all triggers, indexes and whatnots.

Why SSMS will not let you change the propery, I don't know, but it's a
good thing that it does. SSMS would generate the kind of update I
described above. And had SSMS done it right, it would have been a good
thing, but the true story is that a number of serious bugs with that
script engine. I strongly advice you to implement all table changes
with ALTER TABLE.




--
Erland Sommarskog, SQL Server MVP, esquel (AT) sommarskog (DOT) se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx


Reply With Quote
  #3  
Old   
Mike
 
Posts: n/a

Default Re: SQL Express - Identity specification property - how to change - 11-24-2007 , 02:26 AM




I want to use Identity specification because I'd like to get
autoincremental values started from 1 to n

Now, for ID i get some values like 2347658...

I want to set as follows:
data type "int" (or other numeric type),
Identity=Yes,
Identity Seed=1 and Identity Increement=1

On Fri, 23 Nov 2007 22:29:19 +0000 (UTC), Erland Sommarskog
<esquel (AT) sommarskog (DOT) se> wrote:

Quote:
Identity specification

Reply With Quote
  #4  
Old   
Erland Sommarskog
 
Posts: n/a

Default Re: SQL Express - Identity specification property - how to change - 11-24-2007 , 11:25 AM



Mike (ablyplus (AT) yahoo (DOT) com) writes:
Quote:
I want to use Identity specification because I'd like to get
autoincremental values started from 1 to n
For the existing data? Why? Assuming that the id is an artificial key,
the values are of no importance, and 5 is as good as 98987.




--
Erland Sommarskog, SQL Server MVP, esquel (AT) sommarskog (DOT) se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx


Reply With Quote
  #5  
Old   
Mike
 
Posts: n/a

Default Re: SQL Express - Identity specification property - how to change - 11-24-2007 , 12:39 PM



For me is important to be 1,2,3,4,5,6 ... because it is important for
the business logic of application, now, I have some random values
instead.

Please, help me, what is the best way to do that.

Thanks
On Sat, 24 Nov 2007 17:25:24 +0000 (UTC), Erland Sommarskog
<esquel (AT) sommarskog (DOT) se> wrote:

Quote:
Mike (ablyplus (AT) yahoo (DOT) com) writes:
I want to use Identity specification because I'd like to get
autoincremental values started from 1 to n

For the existing data? Why? Assuming that the id is an artificial key,
the values are of no importance, and 5 is as good as 98987.

Reply With Quote
  #6  
Old   
Ed Murphy
 
Posts: n/a

Default Re: SQL Express - Identity specification property - how to change - 11-24-2007 , 01:44 PM



Mike wrote:

Quote:
For me is important to be 1,2,3,4,5,6 ... because it is important for
the business logic of application, now, I have some random values
instead.

Please, help me, what is the best way to do that.
Fix the application. Failing that, I think this will work:

1) Empty the table
2) Follow instructions at http://doc.ddart.net/mssql/sql70/dbcc_5.htm
3) Reload the table


Reply With Quote
  #7  
Old   
Eric J. Holtman
 
Posts: n/a

Default Re: SQL Express - Identity specification property - how to change - 11-24-2007 , 02:38 PM



Mike <ablyplus (AT) yahoo (DOT) com> wrote in news:urrgk3h811nj02q97ifojjlvvoaelkvkmm@
4ax.com:

Quote:
For me is important to be 1,2,3,4,5,6 ... because it is important for
the business logic of application, now, I have some random values
instead.

Then you don't want to use IDENTITY. You'll just end up
with this problem later, over all again.

Don't be stubborn.... FIX THE APPLICATION.



Reply With Quote
  #8  
Old   
Erland Sommarskog
 
Posts: n/a

Default Re: SQL Express - Identity specification property - how to change - 11-24-2007 , 05:23 PM



Mike (ablyplus (AT) yahoo (DOT) com) writes:
Quote:
For me is important to be 1,2,3,4,5,6 ... because it is important for
the business logic of application, now, I have some random values
instead.
So you need the series to be continuous? That is, gaps are not
permitted? In such case you must not use IDENTITY. Watch this:

CREATE TABLE myident(a int IDENTITY,
b int NOT NULL)
go
INSERT myident(b) VALUES (12)
INSERT myident(b) VALUES (NULL)
INSERT myident(b) VALUES (122)
go
SELECT * FROM myident ORDER BY a
go
DROP TABLE myident

An IDENTITY value is "consumed" no matter the INSERT succeeds or
not. And this is precisely why IDENTITY is good for scalability: there
is no number that is locked and which causes serialisation.

If you what to change the ID to be a running number, you can do this
with the existing data:

UPDATE tbl
SET ID = b.rowno
FROM tbl a
JOIN (SELECT ID, rowno = row_number() OVER(ORDER BY ID)
FROM tbl b) ON a.ID = b.ID

But do this first in BEGIN/ROLLBACK TRANSACTION, because I did not test it.

As for assigning new ids, please review my previous post in thread.

Quote:
Please, help me, what is the best way to do that.
I said previously that you needed to rebuild the table, but that is
not true. You can use ALTER TABLE ALTER COLUMN to add an IDENTITY column,
and then use ALTER TABLE DROP COLUMN to get rid of the old. Finally,
use sp_rename to rename the column.

But whatever: do under no circumstances use the table-designer GUI
in Mgmt Studio. It is not reliable.

--
Erland Sommarskog, SQL Server MVP, esquel (AT) sommarskog (DOT) se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx


Reply With Quote
  #9  
Old   
--CELKO--
 
Posts: n/a

Default Re: SQL Express - Identity specification property - how to change - 11-25-2007 , 12:53 PM



I think that you missed the concept of IDENTITY and the Relational
Model. A data type in SQL has to:

1) NULL-able
2) More than one column can have the same data type
3) Has to take CHECK() constraints
4) Appropriate computations can done on it (numeric, string or
temporal)

IDENTITY has none of the properties of a data type because it is not a
data type at all. It is an exposed physical locator attached to a
table, not a property of a column. It is derived from the physical
storage used on one machine, like pointer chains in the old
navigational DBs or row_ids or hash tables.

Quote:
For me is important to be 1,2,3,4,5,6 ... because it is important for the business logic of application, now, I have some random values instead.
What does this mean in your Logical data model? Since it has to
reference something in the reality of that data model to be a valid
RDBMS, how do you validate and verify it?

I would guess that you do none of these basic things, but are
mimicking a sequential tape file application which depends on counting
records in procedural code. Do you have cursors, too?

The whole idea of SQL is to use sets and declarative code. This is
probably just the tip of the iceberg and all you will have is more and
more kludges piled on each other. The thing will run for awhile, but
it will choke from lack of data integrity or the inability to scale up
or to port to another platform.

Fix the design, then fix the application.


Reply With Quote
  #10  
Old   
Tony Rogerson
 
Posts: n/a

Default Re: SQL Express - Identity specification property - how to change - 11-26-2007 , 03:12 PM



Quote:
1) NULL-able
2) More than one column can have the same data type
3) Has to take CHECK() constraints
4) Appropriate computations can done on it (numeric, string or
temporal)

IDENTITY has none of the properties of a data type because it is not a
data type at all.
IDENTITY is a property that we give to one column in the table in the same
vain that we can only give the PRIMARY KEY property to one column in the
table.

The column that has the IDENTITY property can have all the aspects you speek
of - you are compeltely wrong.

Quote:
It is an exposed physical locator attached to a
table, not a property of a column.
Rubbish, it's the property of the column.

Will you PLEASE RTFM and STOP guessing!

Quote:
It is derived from the physical
storage used on one machine, like pointer chains in the old
navigational DBs or row_ids or hash tables.

What total utter rubbish.

People use IDENTITY successfully for surrogate key and they follow all
Codd's rules for surrogates - but the DB world has moved on from Codd's
original definitions - see Date and others for a start.

--
Tony Rogerson, SQL Server MVP
http://sqlblogcasts.com/blogs/tonyrogerson
[Ramblings from the field from a SQL consultant]
http://sqlserverfaq.com
[UK SQL User Community]


"--CELKO--" <jcelko212 (AT) earthlink (DOT) net> wrote

Quote:
I think that you missed the concept of IDENTITY and the Relational
Model. A data type in SQL has to:

1) NULL-able
2) More than one column can have the same data type
3) Has to take CHECK() constraints
4) Appropriate computations can done on it (numeric, string or
temporal)

IDENTITY has none of the properties of a data type because it is not a
data type at all. It is an exposed physical locator attached to a
table, not a property of a column. It is derived from the physical
storage used on one machine, like pointer chains in the old
navigational DBs or row_ids or hash tables.

For me is important to be 1,2,3,4,5,6 ... because it is important for
the business logic of application, now, I have some random values
instead.

What does this mean in your Logical data model? Since it has to
reference something in the reality of that data model to be a valid
RDBMS, how do you validate and verify it?

I would guess that you do none of these basic things, but are
mimicking a sequential tape file application which depends on counting
records in procedural code. Do you have cursors, too?

The whole idea of SQL is to use sets and declarative code. This is
probably just the tip of the iceberg and all you will have is more and
more kludges piled on each other. The thing will run for awhile, but
it will choke from lack of data integrity or the inability to scale up
or to port to another platform.

Fix the design, then fix the application.


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.