Solved

IDENTITY COLUMN AT SQL

Posted on 2011-03-17
9
359 Views
Last Modified: 2012-05-11
Hi All,

I create a identity column :

IdNo SmallInt IDENTITY(4,1)

I have some questions about it :

1. What does it mean ? How many number is the max number ?
2. How to call it using criteria ?

Thank you.
0
Comment
Question by:emi_sastra
  • 3
  • 3
  • 2
  • +1
9 Comments
 
LVL 22

Accepted Solution

by:
Kelvin Sparks earned 200 total points
ID: 35154909
It is an autonumbering column - in your case it will start from 4, and add 1 to the last used number. Generally used with int insteadof smallint. Provides a unique numbering of records - often for primary keys.

You don't call it

Kelvin
0
 
LVL 3

Assisted Solution

by:greisch
greisch earned 200 total points
ID: 35154927
0
 
LVL 1

Author Comment

by:emi_sastra
ID: 35154954
Hi All,

What I mean call it means how to select it using query ?

What is the maximum number for Int and SmallInt ?

Thank you.
0
 
LVL 13

Expert Comment

by:agarwalrahul
ID: 35154961
It is like this

[IdNo] [smallint] IDENTITY(4,1) NOT NULL,

Means that as kelvin says starts from 4 and add 1 to every time the new record insert in the table, but it cannot take deleted [IdNo] value means say if you have 10 records 1-10 and delete the 10th record and insert new record then the [IdNo] takes the 11 not 10 again.
0
Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
LVL 13

Assisted Solution

by:agarwalrahul
agarwalrahul earned 100 total points
ID: 35154970
Please check the link for all the datatype maximum value:

http://www.sql-server-helper.com/faq/data-types-p01.aspx
0
 
LVL 22

Expert Comment

by:Kelvin Sparks
ID: 35155001
Use it the same as any other field in a query

SELECT IdNo FROM yourtable INNER JOIN anothertable ON youtable.IdNo = anothertable.IDNo1
0
 
LVL 1

Author Comment

by:emi_sastra
ID: 35155010
SELECT * FROM yourtable WHERE IdNo = 10 ?

Thank you.
0
 
LVL 22

Expert Comment

by:Kelvin Sparks
ID: 35155022
Yes
0
 
LVL 1

Author Comment

by:emi_sastra
ID: 35155056
Hi All,

Thank you very much for your help.
0

Featured Post

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
sql Audit table 3 50
How to query LOCK_ESCALATION 4 37
MS SQL export CSV & schedule It 9 44
encyps queries mssql 15 27
In SQL Server, when rows are selected from a table, does it retrieve data in the order in which it is inserted?  Many believe this is the case. Let us try to examine for ourselves with an example. To get started, use the following script, wh…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now