Today I learned a few things about the Identity attribute.
Generally, it's good practice to put an Identity column on every table in the database so there's always a unique records in atleast one column, and because SQL is better at doing JOINs on integers than alphabetical columns. So says our senior database developer.
The first goofy thing I did was create a table with no identity column. I couldn't figure out how to add it after the fact so I dumped the table and started over.
This time I included Identity command in the table creation script.
USE Bands
CREATE TABLE [dbo].[Location](
[Location_ID] [int] IDENTITY(100,100) NOT NULL,
[Statement] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL)
The (100/100) is the amount of incrementation to be added to the base number and seed, or starting point, i.e. my identity will roll in increments of 100 and it will start with 100. If you don't have both an increment and a seed, the script won't run and the table won't be completed.
No comments:
Post a Comment