Connecting Tech Pros Worldwide Help | Site Map

ms access - assigning pk via sql query

Bernie Yaeger
Guest
 
Posts: n/a
#1: Nov 12 '05
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



Trevor Best
Guest
 
Posts: n/a
#2: Nov 12 '05

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?
Alan Webb
Guest
 
Posts: n/a
#3: Nov 12 '05

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]


Trevor Best
Guest
 
Posts: n/a
#4: Nov 12 '05

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