Auto Increment...???

PHTech

Senior Member
Joined
Aug 21, 2006
Messages
588
Reaction score
0
Location
Witbank
Hi there...

Can someone help me creating a table in Visual Studio 2008 using MSSQL 2005 Express...?

I have a table where ID should be the auto increment. I have made the ID collumn (Is Identity) to YES, Identity Increment to 1, AND Identity Seed to 1.

When I input data, it makes the auto increment -1, -2, -3, etc... This doesn't work as I have a related table and then writes in the LINK collumn in the second table, that -1, -2, etc. data...? :confused:

HOW CAN I MAKE IT COUNT 1,2,3,etc and not -1,-2,-3,etc...????????
 
Can you paste the table script here?

I think you should check the properties on the table, that shoudl only happen if your Identity Increment is set to -1.
 
What Shred says...

Right click the table name in the sql manager
"script table as"
"create to"
"clipboard"

Then paste here...
 
OK... But I use Visual Studio 2008 and do not know how to view the code for the tables. I have a server explorer and Data Sources tab, and none of them have the abiliy to make me view the source of the table... :(
 
That's pretty odd... Have never had that happen to me?

Its the first time that I also encounter such on a database... I don't really know what to do, as I am new to Visual Basic and SQL. I have read the walkthroughs and stuff, but none actually provide useful info...

Should I code something in the form(s) or not really...?
 
Three options to generate the script

1. Right click the table in VS, "Generate Create Script to Project"

2. Download the management studio express, it has more functionality.
http://www.microsoft.com/downloads/details.aspx?familyid=C243A5AE-4BD1-4E3D-94B8-5A0F62BF7796

3. Download Database Publishing Wizzard add on for VS
http://www.microsoft.com/downloads/details.aspx?familyid=56E5B1C5-BF17-42E0-A410-371A838E570A

This could be a bug in the Server Explorer, but I never create databases in VS, I always use Management Studio. I recommend using Management Studio instead. I am not currently using Express, so will not be able to try and recreate the problem for you :(
 
Like Shred suggested, download Management Studio Express. It will make your life A LOT easier when managing your databases.
 
Three options to generate the script

1. Right click the table in VS, "Generate Create Script to Project"

2. Download the management studio express, it has more functionality.
http://www.microsoft.com/downloads/details.aspx?familyid=C243A5AE-4BD1-4E3D-94B8-5A0F62BF7796

3. Download Database Publishing Wizzard add on for VS
http://www.microsoft.com/downloads/details.aspx?familyid=56E5B1C5-BF17-42E0-A410-371A838E570A

This could be a bug in the Server Explorer, but I never create databases in VS, I always use Management Studio. I recommend using Management Studio instead. I am not currently using Express, so will not be able to try and recreate the problem for you :(

Thanx man... Busy downloading the SQL Server Manager.

Just weird though, that it keeps throwing the ID as a minus...!?
 
Just a thought... Why doesn't Microsoft Include all this tools in Visual Studio 2008 installation...?
 
Just a thought... Why doesn't Microsoft Include all this tools in Visual Studio 2008 installation...?

SQL Server is not part of VS. SQL Server is a server platform, VS is a development environment.
 
Below is the code for the UserInfo Table:

USE [XCSA3G]
GO
/****** Object: Table [dbo].[UserInfo] Script Date: 04/03/2009 14:09:02 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[UserInfo](
[ID] [int] IDENTITY(1,1) NOT FOR REPLICATION NOT NULL,
[UName] [nvarchar](50) COLLATE Latin1_General_CI_AS NULL,
[USurname] [nvarchar](50) COLLATE Latin1_General_CI_AS NULL,
[SIMTelNo] [nvarchar](50) COLLATE Latin1_General_CI_AS NULL,
[IMEI] [nvarchar](50) COLLATE Latin1_General_CI_AS NULL,
CONSTRAINT [PK_UserInfo] PRIMARY KEY CLUSTERED
(
[ID] ASC
)WITH (PAD_INDEX = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
 
This seems very strange hey, the script looks fine.

I would just suggest downloading Management Studio. Its only 30mb. Also, just make sure that you are connecting to the right DB, maybe you have an old version somewhere that you are connecting to that may have the -1.
 
I do - look at the calendar. It's FRIDAY. The DB is incrementing backwards because its urging PHTech to go home for the weekend...

LOL...! :D

I also think that...!

Hey guys... Thanx ALL for all your help...!!! I will apply all your help and most definately follow all your steps...

Have a nice weekend...!
 
Now that's the spirit... Go enjoy the weekend and forget about it until Monday. That's what I'm gonna do now. I have tons of work, but I'm just whiling away the last minutes to be off... :D
 
Err, that is usually when you add a new field that it's -1, -2, etc. when you save the DBMS will assign a value. So in other words, you add a new field and it's ID is -1, you add another it's -2, then you save and it is COMMITTED, at that point is will no longer be negative, else post code and I'll help you.
 
Top
Sign up to the MyBroadband newsletter
X