How do I make a Primary Key in a table automatically increment as a new row of data is entered? do i have to do it with a trigger?? if so what is the code behind it...what I have is a Applicant table, which holds the ApplicantID (<<<needs auto incremented), FirstName, LastName, Address, City, State, Zip, and PhoneNumber. I enter all the other information through visual web developer, and what I need to do when the hit submit on the form with the data i want to automatically set an id right there. any suggestions will help!
If you want an easy way of setting an auto-increment id, use an IDENTITY column. You can use this with smallint, int, etc. You can set the seed (starting value) and the increment value (i.e. by add one to the previous value). You don't have to set a default or increment it yourself.
|||Where do i go to set the column if already created to an identity column?? this is how i created the table, when in Enterprise manager i went the database folder name, expanded the tables and then right clicked and choose add new table...maybe that is the way to do it, but it gave me a design view...and i just made the column a primary key...how do i make it an identity column?
|||Right click the table and choose 'Design Table' in SQL Server 2000, 'Modify Table' in 2005. The lower configuration pane is where you set it. Select your column, and you'll notice there's an 'Identity' property. Set this to Yes/True, and then you can set the sub properties (Identity Seed and Identity Increment).
No comments:
Post a Comment