Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase «««1234»»

An Identity Crisis Expand / Collapse
Author
Message
Posted Wednesday, March 23, 2005 7:54 PM
SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: Tuesday, September 16, 2014 1:00 PM
Points: 421, Visits: 364

I mentioned 3 points... Unfortunately all negative points:

1.  The crisis is nothing to do with Identity.  It is regarding DB design. I believe all agree on that. 

2. This is about the various ways you can identify identity values.  Unless we have a performance issue or do are planning to modify the system entries, using system functions is the best way to retrieve the identity value. This point leads to the third argument.

3. I am sure Performance is not an issue in identifying the identity column, and current value. Is the author planning to change the values? Yes.  If he is going to manipulate system tables, those information are useful.  Otherwise what’s the point of accessing system tables? That is my final argument.  How these system table values helped him to change the data type. Unless he specifies that, that part is not useful.

I am sorry, The article isn't useful to me.



Cheers,
Prithiviraj Kulasingham

http://preethiviraj.blogspot.com/
Post #169730
Posted Wednesday, March 23, 2005 8:08 PM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Monday, April 25, 2005 3:45 AM
Points: 32, Visits: 1

The is also a SQLServer function called COLUMNPROPERTY that you can use to find Identity colums.  Try the following :

Select O.name as [Table],
       C.name as [Column],
       T.name as [Type]
from sysobjects O
join syscolumns C on (C.id=O.id)
join systypes T   on (T.xtype=C.xtype)
where COLUMNPROPERTY(O.id, C.name, 'IsIdentity')=1
and O.type = 'U'




Post #169733
Posted Wednesday, March 23, 2005 8:47 PM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Friday, December 5, 2014 5:54 PM
Points: 1,341, Visits: 805

It's true that the problem can crop up on non-identity columns. I acknowledged that in a previous post on this thread.

However, I think most autoincrement solutions use the Identity property as a means of implementation. Therefore, the problem of an autoincrementing column overflowing the datatype's boundaries is most likely to occur on an Identity column.

I have completed and submitted a script which will grab the maximum value for all integer columns on user tables within a database. Once the script has undergone the sqlservercentral.com vetting process, I'll post the link.

 

TroyK




Post #169734
Posted Wednesday, March 23, 2005 9:01 PM
SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: Tuesday, September 16, 2014 1:00 PM
Points: 421, Visits: 364

My apologies...  Just a few minutes back I found another area where we need to access system tables:  to identify current identity values on linked server. you article is usefull in that ara, as most of the system functions won't work across servers.

 

 



Cheers,
Prithiviraj Kulasingham

http://preethiviraj.blogspot.com/
Post #169736
Posted Thursday, March 24, 2005 6:56 AM
SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: Wednesday, December 5, 2012 3:55 PM
Points: 442, Visits: 185

The following way to find indentities is returning invalid results:


SELECT table_name, column_name, ordinal_position orgPostion, data_type
  FROM INFORMATION_SCHEMA.COLUMNS (NOLOCK)
 where COLUMNPROPERTY (OBJECT_ID(Table_Name),Column_Name,'IsIdentity') = 1
order by table_name, column_name

It returns an integer field from a view as an identity.  The source of this view is a table in another database.  The base table does not have an identity defined.  The field is an "int not null."

You will need to filter out views.

 

 

Post #169836
Posted Thursday, March 24, 2005 7:43 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Tuesday, December 9, 2014 5:36 AM
Points: 5,956, Visits: 286

... and if that still isn't enough, and you know in advance that you need to keep a row for almost every single grain of sand in the Sahara, you can do something like:

create table decimal_t
(
     col1 decimal(38,0) identity(-99999999999999999999999999999999999999, 1)
)



--
Frank Kalis
Microsoft SQL Server MVP
Webmaster: http://www.insidesql.org/blogs
My blog: http://www.insidesql.org/blogs/frankkalis/
Post #169851
Posted Thursday, March 24, 2005 7:46 AM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Friday, December 19, 2014 1:51 PM
Points: 1,113, Visits: 707
And if you need even MORE, you can use the large number libraries posted on my blog

--
Adam Machanic
SQL Server MVP
SQLblog.com: THE SQL Server Blog Spot on the Web
Post #169852
Posted Thursday, March 24, 2005 7:54 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Tuesday, December 9, 2014 5:36 AM
Points: 5,956, Visits: 286

Haha, for qualifying this as a shameless plug, you forgot to post the URL.

 



--
Frank Kalis
Microsoft SQL Server MVP
Webmaster: http://www.insidesql.org/blogs
My blog: http://www.insidesql.org/blogs/frankkalis/
Post #169853
Posted Thursday, March 24, 2005 7:58 AM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Friday, December 19, 2014 1:51 PM
Points: 1,113, Visits: 707
It wasn't a shameless plug -- I would hope that no one would ever actually use it!

--
Adam Machanic
SQL Server MVP
SQLblog.com: THE SQL Server Blog Spot on the Web
Post #169854
Posted Thursday, March 24, 2005 7:58 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Monday, August 4, 2014 7:59 AM
Points: 40, Visits: 49

A better version of the code from my previous post

SELECT T.TABLE_SCHEMA, T.TABLE_NAME, C.COLUMN_NAME, C.DATA_TYPE,
       IDENT_CURRENT(T.TABLE_SCHEMA + '.' + T.TABLE_NAME) [CURRENT_IDENTITY_VALUE]
FROM INFORMATION_SCHEMA.TABLES AS T (NOLOCK)
        INNER JOIN INFORMATION_SCHEMA.COLUMNS AS C (NOLOCK) 
        ON C.TABLE_SCHEMA = T.TABLE_SCHEMA AND C.TABLE_NAME = T.TABLE_NAME
WHERE T.TABLE_TYPE = 'BASE TABLE'
 AND  COLUMNPROPERTY (OBJECT_ID(T.TABLE_SCHEMA + '.' + T.TABLE_NAME), C.COLUMN_NAME, 'IsIdentity') = 1
ORDER BY T.TABLE_SCHEMA, T.TABLE_NAME, C.COLUMN_NAME

--Peter

Post #169855
« Prev Topic | Next Topic »

Add to briefcase «««1234»»

Permissions Expand / Collapse