|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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. |
|
#2
|
|||
|
|||
|
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 ..... ) |
|
#3
|
|||
|
|||
|
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:
|
![]() |
| Viewing: Dev Shed Forums > Databases > MS SQL Development > Automating Incrementation in Primary Key ID field |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|