MS SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesMS SQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old September 18th, 2004, 04:03 AM
thall89553 thall89553 is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jan 2004
Location: Budapest
Posts: 1,431 thall89553 User rank is Private First Class (20 - 50 Reputation Level)thall89553 User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 4 Days 16 h 23 m 21 sec
Reputation Power: 6
Send a message via Yahoo to thall89553
Automating Incrementation in Primary Key ID field

I'm really puzzled with this. I am new to using MS SQL and need help with the primary key. When I was using Access, I would open the database table and just enter values for the various columns, each time a new column was begun, the computer would insert a unique number there. OK, so now I am using visual studio to work on a SQL database. I created a new table and the first field I specified was "ID", I then chose it as the primary key. For default value, I tried both auto number and auto increment. These don't seem to work, as when I type values into fields and try to move to the next row, having left the ID field blank, I get an error which reads "String or Binary data may be truncated". What is going on, what do I need to do so the field automatically populates with an ID number... Some research sort of led me to the concept of a "trigger" to do this. Is this the approach. I was able to r-click on the table and I saw an option for "create trigger" or "new trigger"... How do I learn to do this, is there a generic trigger to do an auto increment of a primary key ID field?
__________________
Today the world, tomorrow the universe...

Last edited by thall89553 : September 18th, 2004 at 04:31 AM.

Reply With Quote
  #2  
Old September 18th, 2004, 04:40 AM
Username=NULL Username=NULL is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Location: TX
Posts: 249 Username=NULL User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 7 h 6 m 42 sec
Reputation Power: 5
Send a message via Yahoo to Username=NULL
I rarely populate the table manually like that, so I'm not very familiar w/that feature in SQL Server. What you're trying to do calls for the field to be declared as IDENTITY, that's the parallel to MS Access AutoNumber. When you clicked, see if that's anywhere in there. Else you could always script out a create table statement and see if that would do the trick.
Code:
create table myTable
(
  ID  [int] [Identity]
  otherField [varchar(30)]
  otherField2 .....
)

Reply With Quote
  #3  
Old September 18th, 2004, 04:53 AM
thall89553 thall89553 is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jan 2004
Location: Budapest
Posts: 1,431 thall89553 User rank is Private First Class (20 - 50 Reputation Level)thall89553 User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 4 Days 16 h 23 m 21 sec
Reputation Power: 6
Send a message via Yahoo to thall89553
Thanks

I don't see one called Identity, but I do see one called UniqueIdentifer... I have been digging around the database and found a table that has a primary key, and for default value, there is a function call, such as (newid()) Looking at the id's for that table, they are very long and complex, surrounded by { ....ID HERE....}

Quote:
Originally Posted by Username=NULL
I rarely populate the table manually like that, so I'm not very familiar w/that feature in SQL Server. What you're trying to do calls for the field to be declared as IDENTITY, that's the parallel to MS Access AutoNumber. When you clicked, see if that's anywhere in there. Else you could always script out a create table statement and see if that would do the trick.
Code:
create table myTable
(
  ID  [int] [Identity]
  otherField [varchar(30)]
  otherField2 .....
)

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMS SQL Development > Automating Incrementation in Primary Key ID field


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
Stay green...Green IT