Home All Groups Group Topic Archive Search About
Author
13 May 2005 11:00 PM
Laura K
I have a table with only about 40 rows.  For some reason we accidentally
forgot the primary key.  Is it possible to add a column to this table that
adds a number to each row and also adds an increment of 1 when a new item is
added.  While we are at it can we make this the primary key column.

I am new at this but I will take a stab. Maybe someone can look at my syntax
and tell me if I am on the right track.

the table name is tblProductSubcategories the column I need to add will be
called intSubcategoryID

Here is my go at it.

Alter Table tblProductSubcategories
Add
intSubcategoryID     int    identity     not null


I know that is not exactly what is needed.  Can someone help me with this
syntax.  Much appreciated.

Laura K

Author
13 May 2005 11:09 PM
--CELKO--
>> I have a table with only about 40 rows.  For some reason we
accidentally forgot the primary key. <<

That is not an accident; that is a major design flaw.

>>  Is it possible to add a column to this table that adds a number to
each row and also adds an increment of 1 when a new item is added.
While we are at it can we make this the primary key column.  <<

BY DEFINITION this is not a primary key!!  Start over and do a real
design.
Author
13 May 2005 11:55 PM
Laura K
WOW you are so very helpful.  I wish everyone could be as dramatic as you.
It really helps moral.

Laura K



Show quote
"--CELKO--" <jcelko***@earthlink.net> wrote in message
news:1116025782.902845.162170@f14g2000cwb.googlegroups.com...
>>> I have a table with only about 40 rows.  For some reason we
> accidentally forgot the primary key. <<
>
> That is not an accident; that is a major design flaw.
>
>>>  Is it possible to add a column to this table that adds a number to
> each row and also adds an increment of 1 when a new item is added.
> While we are at it can we make this the primary key column.  <<
>
> BY DEFINITION this is not a primary key!!  Start over and do a real
> design.
>
Author
14 May 2005 12:12 AM
--CELKO--
My purpose is not to make you feel good.  One of my purposes on
newsgroups is to keep incompetent progammers from killing people. But
all that matters in your world is your feelings, isn't it?

If you don't know me or understand that statement, then Google prior
postings about how people who screwed up schema designs by not knowing
what 1NF was and a medical supply program to Africa I consulted on.

You will probably kludge it with an IDENTITY column.  But it needs a
total re-design.
Author
14 May 2005 12:33 AM
CBretana
Joe, 

    Jeez, -- Only "killing people"? 
    You mean the fate of the entire space-time continumn is not at risk from
the use of Identity columns ?  What a relief!! And all this time I thought...
THis is really good news !!

<grin>
Charly

Show quote
"--CELKO--" wrote:

> My purpose is not to make you feel good.  One of my purposes on
> newsgroups is to keep incompetent progammers from killing people. But
> all that matters in your world is your feelings, isn't it?
>
> If you don't know me or understand that statement, then Google prior
> postings about how people who screwed up schema designs by not knowing
> what 1NF was and a medical supply program to Africa I consulted on.
>
> You will probably kludge it with an IDENTITY column.  But it needs a
> total re-design.
>
>
Author
14 May 2005 2:03 AM
Armando Prato
My grandmother had a saying in Italian that loosely translated
to the following

"you are more respected when you serve wine rather than vinegar".

She's learning.  Heck, I'm learning every day. You could be more diplomatic.


Show quote
"--CELKO--" <jcelko***@earthlink.net> wrote in message
news:1116029573.400380.83040@z14g2000cwz.googlegroups.com...
> My purpose is not to make you feel good.  One of my purposes on
> newsgroups is to keep incompetent progammers from killing people. But
> all that matters in your world is your feelings, isn't it?
>
> If you don't know me or understand that statement, then Google prior
> postings about how people who screwed up schema designs by not knowing
> what 1NF was and a medical supply program to Africa I consulted on.
>
> You will probably kludge it with an IDENTITY column.  But it needs a
> total re-design.
>
Author
14 May 2005 4:38 AM
Laura K
Oh give me a friggen break.  I am the app developer and this was not my
database. I am a programmer NOT a database developer. Guess who is in here
change the schema BEFORE we finish the application.  We are still in
development.  Also our clothing sales are not going to kill anyone unless
perhaps a very large box falls off the shelf.   It is not my feelings.  It
is your lack of consideration.  Don't assume you know what is going on.

" One of my purposes on newsgroups is to keep incompetent programmers from
killing people"

Get over yourself.  You are not that important.

Laura

Show quote
"--CELKO--" <jcelko***@earthlink.net> wrote in message
news:1116029573.400380.83040@z14g2000cwz.googlegroups.com...
> My purpose is not to make you feel good.  One of my purposes on
> newsgroups is to keep incompetent progammers from killing people. But
> all that matters in your world is your feelings, isn't it?
>
> If you don't know me or understand that statement, then Google prior
> postings about how people who screwed up schema designs by not knowing
> what 1NF was and a medical supply program to Africa I consulted on.
>
> You will probably kludge it with an IDENTITY column.  But it needs a
> total re-design.
>
Author
14 May 2005 9:50 PM
Thomas Coleman
> My purpose is not to make you feel good.  One of my purposes on
> newsgroups is to keep incompetent progammers from killing people. But
> all that matters in your world is your feelings, isn't it?

"Killing" people?! Seriously Joe. Sit down, grab a 'lude or ten and chill.
Software develop is not the end of the world or even the end of life.


Thomas

"With tact like that, it's no wonder you're an engineer"
Author
13 May 2005 11:16 PM
Lionel
It's almost done.  You just forgot the primary key.  Try this

------------
Alter Table tblProductSubcategories
Add
intSubcategoryID     int    identity     not null <B>PRIMARY KEY</B>
------------


Lionel


Show quote
"Laura K" wrote:

> I have a table with only about 40 rows.  For some reason we accidentally
> forgot the primary key.  Is it possible to add a column to this table that
> adds a number to each row and also adds an increment of 1 when a new item is
> added.  While we are at it can we make this the primary key column.
>
> I am new at this but I will take a stab. Maybe someone can look at my syntax
> and tell me if I am on the right track.
>
> the table name is tblProductSubcategories the column I need to add will be
> called intSubcategoryID
>
> Here is my go at it.
>
> Alter Table tblProductSubcategories
> Add
> intSubcategoryID     int    identity     not null
>
>
> I know that is not exactly what is needed.  Can someone help me with this
> syntax.  Much appreciated.
>
> Laura K
>
>
>
Author
13 May 2005 11:30 PM
Lionel
Sorry, i forgot to remove the html tags from my answer.  It should read:

Alter Table Employee
Add
intSubcategoryID     int    identity     not null  PRIMARY KEY

Lionel

Show quote
"Lionel" wrote:

> It's almost done.  You just forgot the primary key.  Try this
>
> ------------
> Alter Table tblProductSubcategories
> Add
> intSubcategoryID     int    identity     not null <B>PRIMARY KEY</B>
> ------------
>
>
> Lionel
>
>
> "Laura K" wrote:
>
> > I have a table with only about 40 rows.  For some reason we accidentally
> > forgot the primary key.  Is it possible to add a column to this table that
> > adds a number to each row and also adds an increment of 1 when a new item is
> > added.  While we are at it can we make this the primary key column.
> >
> > I am new at this but I will take a stab. Maybe someone can look at my syntax
> > and tell me if I am on the right track.
> >
> > the table name is tblProductSubcategories the column I need to add will be
> > called intSubcategoryID
> >
> > Here is my go at it.
> >
> > Alter Table tblProductSubcategories
> > Add
> > intSubcategoryID     int    identity     not null
> >
> >
> > I know that is not exactly what is needed.  Can someone help me with this
> > syntax.  Much appreciated.
> >
> > Laura K
> >
> >
> >
Author
13 May 2005 11:28 PM
CBretana
YES!! Just add another Column defined as Integer Identity... Say it's
Customers table, and the new PK will be CustomerID...

Alter Table Customers 
(Add Column CustomerID Integer Identity Primary Key Not Null)

And there's NOTHING at all wrong with using this type of Primary Key...  But
you should also, if at all possible, add another "key" in the form of a
unique constrraint or index, on whichever combination of "real" data columns
uniquely identifies each row... This will prevent the additon of two rows
(with different Idnetity values) from being added that represent the same
real world business object. 



Show quote
"Laura K" wrote:

> I have a table with only about 40 rows.  For some reason we accidentally
> forgot the primary key.  Is it possible to add a column to this table that
> adds a number to each row and also adds an increment of 1 when a new item is
> added.  While we are at it can we make this the primary key column.
>
> I am new at this but I will take a stab. Maybe someone can look at my syntax
> and tell me if I am on the right track.
>
> the table name is tblProductSubcategories the column I need to add will be
> called intSubcategoryID
>
> Here is my go at it.
>
> Alter Table tblProductSubcategories
> Add
> intSubcategoryID     int    identity     not null
>
>
> I know that is not exactly what is needed.  Can someone help me with this
> syntax.  Much appreciated.
>
> Laura K
>
>
>
Author
13 May 2005 11:30 PM
CBretana
Laura,
   YES, you can!! Just add another Column defined as "Integer Identity
Primary Key"... Say it's Customers table, and the new PK will be CustomerID...

Alter Table Customers 
(Add Column CustomerID Integer Identity Primary Key Not Null)

And there's NOTHING at all wrong with using this type of Primary Key...  But
you should also, if at all possible, add another "key" in the form of a
unique constrraint or index, on whichever combination of "real" data columns
uniquely identifies each row... This will prevent the additon of two rows
(with different Idnetity values) from being added that represent the same
real world business object. 


Show quote
"Laura K" wrote:

> I have a table with only about 40 rows.  For some reason we accidentally
> forgot the primary key.  Is it possible to add a column to this table that
> adds a number to each row and also adds an increment of 1 when a new item is
> added.  While we are at it can we make this the primary key column.
>
> I am new at this but I will take a stab. Maybe someone can look at my syntax
> and tell me if I am on the right track.
>
> the table name is tblProductSubcategories the column I need to add will be
> called intSubcategoryID
>
> Here is my go at it.
>
> Alter Table tblProductSubcategories
> Add
> intSubcategoryID     int    identity     not null
>
>
> I know that is not exactly what is needed.  Can someone help me with this
> syntax.  Much appreciated.
>
> Laura K
>
>
>
Author
13 May 2005 11:54 PM
Laura K
Thanks all will give it a try  this evening.  We actually didn't forget the
PK.  We decided to use the subcat name but as I designed I got frustrated
with not having a number.  Thus the change.  Now when I do this will it add
the numbers incrementally to all 40 rows.

Laura



Show quote
"CBretana" <cbretana@areteIndNOSPAM.com> wrote in message
news:C8B1B527-538E-438C-A19A-26E665C25645@microsoft.com...
> Laura,
>   YES, you can!! Just add another Column defined as "Integer Identity
> Primary Key"... Say it's Customers table, and the new PK will be
> CustomerID...
>
> Alter Table Customers
> (Add Column CustomerID Integer Identity Primary Key Not Null)
>
> And there's NOTHING at all wrong with using this type of Primary Key...
> But
> you should also, if at all possible, add another "key" in the form of a
> unique constrraint or index, on whichever combination of "real" data
> columns
> uniquely identifies each row... This will prevent the additon of two rows
> (with different Idnetity values) from being added that represent the same
> real world business object.
>
>
> "Laura K" wrote:
>
>> I have a table with only about 40 rows.  For some reason we accidentally
>> forgot the primary key.  Is it possible to add a column to this table
>> that
>> adds a number to each row and also adds an increment of 1 when a new item
>> is
>> added.  While we are at it can we make this the primary key column.
>>
>> I am new at this but I will take a stab. Maybe someone can look at my
>> syntax
>> and tell me if I am on the right track.
>>
>> the table name is tblProductSubcategories the column I need to add will
>> be
>> called intSubcategoryID
>>
>> Here is my go at it.
>>
>> Alter Table tblProductSubcategories
>> Add
>> intSubcategoryID     int    identity     not null
>>
>>
>> I know that is not exactly what is needed.  Can someone help me with this
>> syntax.  Much appreciated.
>>
>> Laura K
>>
>>
>>
Author
14 May 2005 12:04 AM
CBretana
Yes, Although the order will be arbitrary... If you want the records
"numbered" in a specific Order, then you need to do something a bit
different... RU interested int that?

(Remember, since this is a "Surrogate" key, the actual value should not be
publicly visible or used by end-users, so the value shouldn't be important,
just that it's unique...) 

Show quote
"Laura K" wrote:

> Thanks all will give it a try  this evening.  We actually didn't forget the
> PK.  We decided to use the subcat name but as I designed I got frustrated
> with not having a number.  Thus the change.  Now when I do this will it add
> the numbers incrementally to all 40 rows.
>
> Laura
>
>
>
> "CBretana" <cbretana@areteIndNOSPAM.com> wrote in message
> news:C8B1B527-538E-438C-A19A-26E665C25645@microsoft.com...
> > Laura,
> >   YES, you can!! Just add another Column defined as "Integer Identity
> > Primary Key"... Say it's Customers table, and the new PK will be
> > CustomerID...
> >
> > Alter Table Customers
> > (Add Column CustomerID Integer Identity Primary Key Not Null)
> >
> > And there's NOTHING at all wrong with using this type of Primary Key...
> > But
> > you should also, if at all possible, add another "key" in the form of a
> > unique constrraint or index, on whichever combination of "real" data
> > columns
> > uniquely identifies each row... This will prevent the additon of two rows
> > (with different Idnetity values) from being added that represent the same
> > real world business object.
> >
> >
> > "Laura K" wrote:
> >
> >> I have a table with only about 40 rows.  For some reason we accidentally
> >> forgot the primary key.  Is it possible to add a column to this table
> >> that
> >> adds a number to each row and also adds an increment of 1 when a new item
> >> is
> >> added.  While we are at it can we make this the primary key column.
> >>
> >> I am new at this but I will take a stab. Maybe someone can look at my
> >> syntax
> >> and tell me if I am on the right track.
> >>
> >> the table name is tblProductSubcategories the column I need to add will
> >> be
> >> called intSubcategoryID
> >>
> >> Here is my go at it.
> >>
> >> Alter Table tblProductSubcategories
> >> Add
> >> intSubcategoryID     int    identity     not null
> >>
> >>
> >> I know that is not exactly what is needed.  Can someone help me with this
> >> syntax.  Much appreciated.
> >>
> >> Laura K
> >>
> >>
> >>
>
>
>
Author
14 May 2005 12:09 AM
Alejandro Mesa
> > > Alter Table Customers
> > > (Add Column CustomerID Integer Identity Primary Key Not Null)

For sure you meant:

Alter Table Customers
Add CustomerID Integer ...


AMB


Show quote
"CBretana" wrote:

> Yes, Although the order will be arbitrary... If you want the records
> "numbered" in a specific Order, then you need to do something a bit
> different... RU interested int that?
>
> (Remember, since this is a "Surrogate" key, the actual value should not be
> publicly visible or used by end-users, so the value shouldn't be important,
> just that it's unique...) 
>
> "Laura K" wrote:
>
> > Thanks all will give it a try  this evening.  We actually didn't forget the
> > PK.  We decided to use the subcat name but as I designed I got frustrated
> > with not having a number.  Thus the change.  Now when I do this will it add
> > the numbers incrementally to all 40 rows.
> >
> > Laura
> >
> >
> >
> > "CBretana" <cbretana@areteIndNOSPAM.com> wrote in message
> > news:C8B1B527-538E-438C-A19A-26E665C25645@microsoft.com...
> > > Laura,
> > >   YES, you can!! Just add another Column defined as "Integer Identity
> > > Primary Key"... Say it's Customers table, and the new PK will be
> > > CustomerID...
> > >
> > > Alter Table Customers
> > > (Add Column CustomerID Integer Identity Primary Key Not Null)
> > >
> > > And there's NOTHING at all wrong with using this type of Primary Key...
> > > But
> > > you should also, if at all possible, add another "key" in the form of a
> > > unique constrraint or index, on whichever combination of "real" data
> > > columns
> > > uniquely identifies each row... This will prevent the additon of two rows
> > > (with different Idnetity values) from being added that represent the same
> > > real world business object.
> > >
> > >
> > > "Laura K" wrote:
> > >
> > >> I have a table with only about 40 rows.  For some reason we accidentally
> > >> forgot the primary key.  Is it possible to add a column to this table
> > >> that
> > >> adds a number to each row and also adds an increment of 1 when a new item
> > >> is
> > >> added.  While we are at it can we make this the primary key column.
> > >>
> > >> I am new at this but I will take a stab. Maybe someone can look at my
> > >> syntax
> > >> and tell me if I am on the right track.
> > >>
> > >> the table name is tblProductSubcategories the column I need to add will
> > >> be
> > >> called intSubcategoryID
> > >>
> > >> Here is my go at it.
> > >>
> > >> Alter Table tblProductSubcategories
> > >> Add
> > >> intSubcategoryID     int    identity     not null
> > >>
> > >>
> > >> I know that is not exactly what is needed.  Can someone help me with this
> > >> syntax.  Much appreciated.
> > >>
> > >> Laura K
> > >>
> > >>
> > >>
> >
> >
> >
Author
14 May 2005 12:28 AM
CBretana
oops, fer sure! Thanks !!

I never use DDL for this... and the syntax in BOL is, imho, atrocious...
Good catch, totl ddl should be:

Alter Table Customers Add CustomerID Integer Identity Primary Key Not Null 
or, for Laura's specific table,

Alter Table tblProductSubcategories
    Add SubCategoryID Integer Identity Primary Key Not Null 


Show quote
"Alejandro Mesa" wrote:

> > > > Alter Table Customers
> > > > (Add Column CustomerID Integer Identity Primary Key Not Null)
>
> For sure you meant:
>
> Alter Table Customers
> Add CustomerID Integer ...
>
>
> AMB
>
>
> "CBretana" wrote:
>
> > Yes, Although the order will be arbitrary... If you want the records
> > "numbered" in a specific Order, then you need to do something a bit
> > different... RU interested int that?
> >
> > (Remember, since this is a "Surrogate" key, the actual value should not be
> > publicly visible or used by end-users, so the value shouldn't be important,
> > just that it's unique...) 
> >
> > "Laura K" wrote:
> >
> > > Thanks all will give it a try  this evening.  We actually didn't forget the
> > > PK.  We decided to use the subcat name but as I designed I got frustrated
> > > with not having a number.  Thus the change.  Now when I do this will it add
> > > the numbers incrementally to all 40 rows.
> > >
> > > Laura
> > >
> > >
> > >
> > > "CBretana" <cbretana@areteIndNOSPAM.com> wrote in message
> > > news:C8B1B527-538E-438C-A19A-26E665C25645@microsoft.com...
> > > > Laura,
> > > >   YES, you can!! Just add another Column defined as "Integer Identity
> > > > Primary Key"... Say it's Customers table, and the new PK will be
> > > > CustomerID...
> > > >
> > > > Alter Table Customers
> > > > (Add Column CustomerID Integer Identity Primary Key Not Null)
> > > >
> > > > And there's NOTHING at all wrong with using this type of Primary Key...
> > > > But
> > > > you should also, if at all possible, add another "key" in the form of a
> > > > unique constrraint or index, on whichever combination of "real" data
> > > > columns
> > > > uniquely identifies each row... This will prevent the additon of two rows
> > > > (with different Idnetity values) from being added that represent the same
> > > > real world business object.
> > > >
> > > >
> > > > "Laura K" wrote:
> > > >
> > > >> I have a table with only about 40 rows.  For some reason we accidentally
> > > >> forgot the primary key.  Is it possible to add a column to this table
> > > >> that
> > > >> adds a number to each row and also adds an increment of 1 when a new item
> > > >> is
> > > >> added.  While we are at it can we make this the primary key column.
> > > >>
> > > >> I am new at this but I will take a stab. Maybe someone can look at my
> > > >> syntax
> > > >> and tell me if I am on the right track.
> > > >>
> > > >> the table name is tblProductSubcategories the column I need to add will
> > > >> be
> > > >> called intSubcategoryID
> > > >>
> > > >> Here is my go at it.
> > > >>
> > > >> Alter Table tblProductSubcategories
> > > >> Add
> > > >> intSubcategoryID     int    identity     not null
> > > >>
> > > >>
> > > >> I know that is not exactly what is needed.  Can someone help me with this
> > > >> syntax.  Much appreciated.
> > > >>
> > > >> Laura K
> > > >>
> > > >>
> > > >>
> > >
> > >
> > >
Author
14 May 2005 4:46 AM
Laura K
Awesome.  It works.

Thanks.   I will try not to cause world disasters from my faulty programming
;)

Laura K




Show quote
"CBretana" <cbretana@areteIndNOSPAM.com> wrote in message
news:A26B2CC0-AEB3-490D-B665-3D4FD7124F10@microsoft.com...
> oops, fer sure! Thanks !!
>
> I never use DDL for this... and the syntax in BOL is, imho, atrocious...
> Good catch, totl ddl should be:
>
> Alter Table Customers Add CustomerID Integer Identity Primary Key Not Null
> or, for Laura's specific table,
>
> Alter Table tblProductSubcategories
>    Add SubCategoryID Integer Identity Primary Key Not Null
>
>
> "Alejandro Mesa" wrote:
>
>> > > > Alter Table Customers
>> > > > (Add Column CustomerID Integer Identity Primary Key Not Null)
>>
>> For sure you meant:
>>
>> Alter Table Customers
>> Add CustomerID Integer ...
>>
>>
>> AMB
>>
>>
>> "CBretana" wrote:
>>
>> > Yes, Although the order will be arbitrary... If you want the records
>> > "numbered" in a specific Order, then you need to do something a bit
>> > different... RU interested int that?
>> >
>> > (Remember, since this is a "Surrogate" key, the actual value should not
>> > be
>> > publicly visible or used by end-users, so the value shouldn't be
>> > important,
>> > just that it's unique...)
>> >
>> > "Laura K" wrote:
>> >
>> > > Thanks all will give it a try  this evening.  We actually didn't
>> > > forget the
>> > > PK.  We decided to use the subcat name but as I designed I got
>> > > frustrated
>> > > with not having a number.  Thus the change.  Now when I do this will
>> > > it add
>> > > the numbers incrementally to all 40 rows.
>> > >
>> > > Laura
>> > >
>> > >
>> > >
>> > > "CBretana" <cbretana@areteIndNOSPAM.com> wrote in message
>> > > news:C8B1B527-538E-438C-A19A-26E665C25645@microsoft.com...
>> > > > Laura,
>> > > >   YES, you can!! Just add another Column defined as "Integer
>> > > > Identity
>> > > > Primary Key"... Say it's Customers table, and the new PK will be
>> > > > CustomerID...
>> > > >
>> > > > Alter Table Customers
>> > > > (Add Column CustomerID Integer Identity Primary Key Not Null)
>> > > >
>> > > > And there's NOTHING at all wrong with using this type of Primary
>> > > > Key...
>> > > > But
>> > > > you should also, if at all possible, add another "key" in the form
>> > > > of a
>> > > > unique constrraint or index, on whichever combination of "real"
>> > > > data
>> > > > columns
>> > > > uniquely identifies each row... This will prevent the additon of
>> > > > two rows
>> > > > (with different Idnetity values) from being added that represent
>> > > > the same
>> > > > real world business object.
>> > > >
>> > > >
>> > > > "Laura K" wrote:
>> > > >
>> > > >> I have a table with only about 40 rows.  For some reason we
>> > > >> accidentally
>> > > >> forgot the primary key.  Is it possible to add a column to this
>> > > >> table
>> > > >> that
>> > > >> adds a number to each row and also adds an increment of 1 when a
>> > > >> new item
>> > > >> is
>> > > >> added.  While we are at it can we make this the primary key
>> > > >> column.
>> > > >>
>> > > >> I am new at this but I will take a stab. Maybe someone can look at
>> > > >> my
>> > > >> syntax
>> > > >> and tell me if I am on the right track.
>> > > >>
>> > > >> the table name is tblProductSubcategories the column I need to add
>> > > >> will
>> > > >> be
>> > > >> called intSubcategoryID
>> > > >>
>> > > >> Here is my go at it.
>> > > >>
>> > > >> Alter Table tblProductSubcategories
>> > > >> Add
>> > > >> intSubcategoryID     int    identity     not null
>> > > >>
>> > > >>
>> > > >> I know that is not exactly what is needed.  Can someone help me
>> > > >> with this
>> > > >> syntax.  Much appreciated.
>> > > >>
>> > > >> Laura K
>> > > >>
>> > > >>
>> > > >>
>> > >
>> > >
>> > >
Author
14 May 2005 2:38 PM
CBretana
yr welcome!   Remember, Life is short, Laugh as much as possible!A few world
disasters along the way is not the end.. ooh, bad metaphor...

Show quote
"Laura K" wrote:

> Awesome.  It works.
>
> Thanks.   I will try not to cause world disasters from my faulty programming
> ;)
>
> Laura K
>
>
>
>
> "CBretana" <cbretana@areteIndNOSPAM.com> wrote in message
> news:A26B2CC0-AEB3-490D-B665-3D4FD7124F10@microsoft.com...
> > oops, fer sure! Thanks !!
> >
> > I never use DDL for this... and the syntax in BOL is, imho, atrocious...
> > Good catch, totl ddl should be:
> >
> > Alter Table Customers Add CustomerID Integer Identity Primary Key Not Null
> > or, for Laura's specific table,
> >
> > Alter Table tblProductSubcategories
> >    Add SubCategoryID Integer Identity Primary Key Not Null
> >
> >
> > "Alejandro Mesa" wrote:
> >
> >> > > > Alter Table Customers
> >> > > > (Add Column CustomerID Integer Identity Primary Key Not Null)
> >>
> >> For sure you meant:
> >>
> >> Alter Table Customers
> >> Add CustomerID Integer ...
> >>
> >>
> >> AMB
> >>
> >>
> >> "CBretana" wrote:
> >>
> >> > Yes, Although the order will be arbitrary... If you want the records
> >> > "numbered" in a specific Order, then you need to do something a bit
> >> > different... RU interested int that?
> >> >
> >> > (Remember, since this is a "Surrogate" key, the actual value should not
> >> > be
> >> > publicly visible or used by end-users, so the value shouldn't be
> >> > important,
> >> > just that it's unique...)
> >> >
> >> > "Laura K" wrote:
> >> >
> >> > > Thanks all will give it a try  this evening.  We actually didn't
> >> > > forget the
> >> > > PK.  We decided to use the subcat name but as I designed I got
> >> > > frustrated
> >> > > with not having a number.  Thus the change.  Now when I do this will
> >> > > it add
> >> > > the numbers incrementally to all 40 rows.
> >> > >
> >> > > Laura
> >> > >
> >> > >
> >> > >
> >> > > "CBretana" <cbretana@areteIndNOSPAM.com> wrote in message
> >> > > news:C8B1B527-538E-438C-A19A-26E665C25645@microsoft.com...
> >> > > > Laura,
> >> > > >   YES, you can!! Just add another Column defined as "Integer
> >> > > > Identity
> >> > > > Primary Key"... Say it's Customers table, and the new PK will be
> >> > > > CustomerID...
> >> > > >
> >> > > > Alter Table Customers
> >> > > > (Add Column CustomerID Integer Identity Primary Key Not Null)
> >> > > >
> >> > > > And there's NOTHING at all wrong with using this type of Primary
> >> > > > Key...
> >> > > > But
> >> > > > you should also, if at all possible, add another "key" in the form
> >> > > > of a
> >> > > > unique constrraint or index, on whichever combination of "real"
> >> > > > data
> >> > > > columns
> >> > > > uniquely identifies each row... This will prevent the additon of
> >> > > > two rows
> >> > > > (with different Idnetity values) from being added that represent
> >> > > > the same
> >> > > > real world business object.
> >> > > >
> >> > > >
> >> > > > "Laura K" wrote:
> >> > > >
> >> > > >> I have a table with only about 40 rows.  For some reason we
> >> > > >> accidentally
> >> > > >> forgot the primary key.  Is it possible to add a column to this
> >> > > >> table
> >> > > >> that
> >> > > >> adds a number to each row and also adds an increment of 1 when a
> >> > > >> new item
> >> > > >> is
> >> > > >> added.  While we are at it can we make this the primary key
> >> > > >> column.
> >> > > >>
> >> > > >> I am new at this but I will take a stab. Maybe someone can look at
> >> > > >> my
> >> > > >> syntax
> >> > > >> and tell me if I am on the right track.
> >> > > >>
> >> > > >> the table name is tblProductSubcategories the column I need to add
> >> > > >> will
> >> > > >> be
> >> > > >> called intSubcategoryID
> >> > > >>
> >> > > >> Here is my go at it.
> >> > > >>
> >> > > >> Alter Table tblProductSubcategories
> >> > > >> Add
> >> > > >> intSubcategoryID     int    identity     not null
> >> > > >>
> >> > > >>
> >> > > >> I know that is not exactly what is needed.  Can someone help me
> >> > > >> with this
> >> > > >> syntax.  Much appreciated.
> >> > > >>
> >> > > >> Laura K
> >> > > >>
> >> > > >>
> >> > > >>
> >> > >
> >> > >
> >> > >
>
>
>
Author
14 May 2005 4:39 AM
Laura K
No the order is not important.  Right now we just have things in
alphabetical order.  It is just a listing of subcategories of clothing.


Show quote
"CBretana" <cbretana@areteIndNOSPAM.com> wrote in message
news:489C285B-E4BF-401D-A76C-BBB715014519@microsoft.com...
> Yes, Although the order will be arbitrary... If you want the records
> "numbered" in a specific Order, then you need to do something a bit
> different... RU interested int that?
>
> (Remember, since this is a "Surrogate" key, the actual value should not be
> publicly visible or used by end-users, so the value shouldn't be
> important,
> just that it's unique...)
>
> "Laura K" wrote:
>
>> Thanks all will give it a try  this evening.  We actually didn't forget
>> the
>> PK.  We decided to use the subcat name but as I designed I got frustrated
>> with not having a number.  Thus the change.  Now when I do this will it
>> add
>> the numbers incrementally to all 40 rows.
>>
>> Laura
>>
>>
>>
>> "CBretana" <cbretana@areteIndNOSPAM.com> wrote in message
>> news:C8B1B527-538E-438C-A19A-26E665C25645@microsoft.com...
>> > Laura,
>> >   YES, you can!! Just add another Column defined as "Integer Identity
>> > Primary Key"... Say it's Customers table, and the new PK will be
>> > CustomerID...
>> >
>> > Alter Table Customers
>> > (Add Column CustomerID Integer Identity Primary Key Not Null)
>> >
>> > And there's NOTHING at all wrong with using this type of Primary Key...
>> > But
>> > you should also, if at all possible, add another "key" in the form of a
>> > unique constrraint or index, on whichever combination of "real" data
>> > columns
>> > uniquely identifies each row... This will prevent the additon of two
>> > rows
>> > (with different Idnetity values) from being added that represent the
>> > same
>> > real world business object.
>> >
>> >
>> > "Laura K" wrote:
>> >
>> >> I have a table with only about 40 rows.  For some reason we
>> >> accidentally
>> >> forgot the primary key.  Is it possible to add a column to this table
>> >> that
>> >> adds a number to each row and also adds an increment of 1 when a new
>> >> item
>> >> is
>> >> added.  While we are at it can we make this the primary key column.
>> >>
>> >> I am new at this but I will take a stab. Maybe someone can look at my
>> >> syntax
>> >> and tell me if I am on the right track.
>> >>
>> >> the table name is tblProductSubcategories the column I need to add
>> >> will
>> >> be
>> >> called intSubcategoryID
>> >>
>> >> Here is my go at it.
>> >>
>> >> Alter Table tblProductSubcategories
>> >> Add
>> >> intSubcategoryID     int    identity     not null
>> >>
>> >>
>> >> I know that is not exactly what is needed.  Can someone help me with
>> >> this
>> >> syntax.  Much appreciated.
>> >>
>> >> Laura K
>> >>
>> >>
>> >>
>>
>>
>>

AddThis Social Bookmark Button