|
-
Oct 5th, 2010, 03:52 PM
#1
Thread Starter
PowerPoster
Auto-Incrementing field in SQL Server?
I am trying to manually add a row of data to a table within SQL Server 2005. The first column, called "MyData_Notes_ID" has the "Is Identity" set to "Yes" (it's also the Primary Key for the table), therefore, I don't include that column in my "INSERT" statement. However, when I execute the statement, it tells me that the "MyData_Notes_ID" field can't be null. What am I doing wrong?
Thanks,
-
Oct 5th, 2010, 04:09 PM
#2
Re: Auto-Incrementing field in SQL Server?
What is the Insert statement?
Sometimes the Programmer
Sometimes the DBA
Mazz1
-
Oct 5th, 2010, 04:21 PM
#3
Thread Starter
PowerPoster
Re: Auto-Incrementing field in SQL Server?
Here ya go Gary,
Code:
Use OA_Runtime
INSERT INTO MyData_Notes
(Category,
Title,
Body,
NTLogin,
isCurrentVersion,
isDeleted,
DateCreated,
DateDeleted)
VALUES
('Address Info',
'Wrong Address',
'This is test record #2',
'Z126409',
0,
0,
GetDate(),
GetDate())
-
Oct 5th, 2010, 04:44 PM
#4
Re: Auto-Incrementing field in SQL Server?
That looks correct. Are you sure that the MyData_Notes_ID is set to IDENTITY?
Sometimes the Programmer
Sometimes the DBA
Mazz1
-
Oct 5th, 2010, 04:46 PM
#5
Thread Starter
PowerPoster
Re: Auto-Incrementing field in SQL Server?
Gary,
I think I found the problem. You can't have more than 1 identity column per table can you? If so, that was my problem...if not, then I don't know! LOL
-
Oct 5th, 2010, 09:04 PM
#6
Re: Auto-Incrementing field in SQL Server?
 Originally Posted by blakemckenna
Gary,
I think I found the problem. You can't have more than 1 identity column per table can you? If so, that was my problem...if not, then I don't know! LOL
That would indeed be the problem. It doesn't make sense to have more than one identity per table. The point of the identity is to uniquely identify each record. Two identities can't do that any better than one, so there's no reason to have two.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|