Connecting Tech Pros Worldwide Help | Site Map

ms access - assigning pk via sql query

  #1  
Old November 12th, 2005, 09:26 PM
Bernie Yaeger
Guest
 
Posts: n/a
Is there a way in MS Access to assign a PK to a table through a query. I am
creating the table with 'select .... into <tablename> from etc' which works
fine, once executed with executenonquery. But I need to give it a pk as
well - how can this be done? BTW- I'm working in vb .net, but the query I
envision would be a simple query in the .mdb itself and I would only execute
it inside vb .net.

Thanks for any help.

Bernie Yaeger



  #2  
Old November 12th, 2005, 09:26 PM
Trevor Best
Guest
 
Posts: n/a

re: ms access - assigning pk via sql query


Bernie Yaeger wrote:[color=blue]
> Is there a way in MS Access to assign a PK to a table through a query. I am
> creating the table with 'select .... into <tablename> from etc' which works
> fine, once executed with executenonquery. But I need to give it a pk as
> well - how can this be done? BTW- I'm working in vb .net, but the query I
> envision would be a simple query in the .mdb itself and I would only execute
> it inside vb .net.
>
> Thanks for any help.
>
> Bernie Yaeger
>
>
>[/color]
ALTER TABLE [TableName] ADD CONSTRAINT
[PrimaryKeyName PRIMARY KEY
(
[PrimaryKeyColumn]
)


--
But why is the Rum gone?
  #3  
Old November 12th, 2005, 09:27 PM
Alan Webb
Guest
 
Posts: n/a

re: ms access - assigning pk via sql query


Bernie,
A CREATE TABLE statement has to come first. So you probably can't do it in
one SQL statement. And Access/Jet queries don't support multiple SQL
statements in one query object so scripting this is a bit of a pain. But,
basically, create the table then use an INSERT statement to populate it.

"Bernie Yaeger" <berniey@cherwellinc.com> wrote in message
news:34N2c.20672$Ak2.7231575@news4.srv.hcvlny.cv.n et...[color=blue]
> Is there a way in MS Access to assign a PK to a table through a query. I[/color]
am[color=blue]
> creating the table with 'select .... into <tablename> from etc' which[/color]
works[color=blue]
> fine, once executed with executenonquery. But I need to give it a pk as
> well - how can this be done? BTW- I'm working in vb .net, but the query I
> envision would be a simple query in the .mdb itself and I would only[/color]
execute[color=blue]
> it inside vb .net.
>
> Thanks for any help.
>
> Bernie Yaeger
>
>
>[/color]


  #4  
Old November 12th, 2005, 09:27 PM
Trevor Best
Guest
 
Posts: n/a

re: ms access - assigning pk via sql query


Trevor Best wrote:
[color=blue]
> Bernie Yaeger wrote:
>[color=green]
>> Is there a way in MS Access to assign a PK to a table through a
>> query. I am
>> creating the table with 'select .... into <tablename> from etc' which
>> works
>> fine, once executed with executenonquery. But I need to give it a pk as
>> well - how can this be done? BTW- I'm working in vb .net, but the
>> query I
>> envision would be a simple query in the .mdb itself and I would only
>> execute
>> it inside vb .net.
>>
>> Thanks for any help.
>>
>> Bernie Yaeger
>>
>>
>>[/color]
> ALTER TABLE [TableName] ADD CONSTRAINT
> [PrimaryKeyName PRIMARY KEY
> (
> [PrimaryKeyColumn]
> )
>
>[/color]
Sorry 'nother typo: should be "[PrimaryKeyName]" with a closing square
bracket.



--
But why is the Rum gone?
Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
Creating Multiple Field on an Event Emax answers 2 September 4th, 2007 02:50 AM
Creating self-join table davegb answers 6 November 13th, 2005 03:00 PM
Enter a Description using scripts in MS-ACCESS doomx answers 8 November 13th, 2005 08:06 AM
Help with corrupt table Dan answers 21 November 12th, 2005 07:10 PM
Access Corruption / MySQL Mike answers 10 November 12th, 2005 04:49 PM