Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Autogenerate a primary key

Author  Topic 

bobshishka
Yak Posting Veteran

72 Posts

Posted - 2007-09-06 : 12:18:05
I have a table that I am constantly updating with data. I would like to have the field SMT_ID be updated with an autonumber that is unique on creation of the record- similar to Access' "AutoNumber" feature.

Currently I am using the "Identity" DataType. This works great, but I need my field length to be more than 4. I need 12.

I cant change this in the "Design Table" properties. How do I change it?

As always- Thanks

Kristen
Test

22859 Posts

Posted - 2007-09-06 : 12:27:24
"I need my field length to be more than 4"

Sounds like you are using an INT datatype? (which is 4 bytes, which has a max value of 256^4, which is probably enough, and certainly more than 4 digits!)

Kristen
Go to Top of Page

bobshishka
Yak Posting Veteran

72 Posts

Posted - 2007-09-06 : 12:35:24
You are correct.... Which datatype will allow me to set the Identity property to "Yes" AND the Length to 12?
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2007-09-06 : 12:42:40
use bigint

_______________________________________________
Causing trouble since 1980
blog: http://weblogs.sqlteam.com/mladenp
Go to Top of Page

bobshishka
Yak Posting Veteran

72 Posts

Posted - 2007-09-06 : 13:01:41
Disregard. Using BigInt will solve my problems. There is no way I will ever get past 99,999,999. Thanks though.
Go to Top of Page

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2007-09-06 : 13:16:34
If you only need numbers to 99,999,999 then INT should work. (why take up more storage than is needed?)

An INT will hold values up to 2,147,483,647 and BIGINT will hold values up to 9,223,372,036,854,775,807.
Go to Top of Page

bobshishka
Yak Posting Veteran

72 Posts

Posted - 2007-09-06 : 13:23:46
In SQL 2000 when I select int as my DataType my field length will not let me go above 4. How can I change this?
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2007-09-06 : 13:27:23
4 is the number of storage bytes not digits.

_______________________________________________
Causing trouble since 1980
blog: http://weblogs.sqlteam.com/mladenp
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2007-09-06 : 14:47:41
"4 is the number of storage bytes not digits."

I thought I said that already, or am I getting old and senile?
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2007-09-06 : 14:54:35
yes but i guess the OP doesn't recognize the difference yet.

_______________________________________________
Causing trouble since 1980
blog: http://weblogs.sqlteam.com/mladenp
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2007-09-06 : 15:16:48
"doesn't recognize the difference yet"

What, between "old" and "senile"?

Remind me: What IS the difference?

No, scratch that, you won't know ... yet!
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2007-09-06 : 15:20:44


_______________________________________________
Causing trouble since 1980
blog: http://weblogs.sqlteam.com/mladenp
Go to Top of Page

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2007-09-06 : 16:53:42
To paraphrase George Burns:

Old is when you bend over to tie your shoes and you look around to see what else you can do while you're down there.
Senile is when you forget why you're down there!

Jim
Go to Top of Page
   

- Advertisement -