Connecting Tech Pros Worldwide Help | Site Map

ms access - assigning pk via sql query

 
LinkBack Thread Tools Search this Thread
  #1  
Old November 12th, 2005, 08:26 PM
Bernie Yaeger
Guest
 
Posts: n/a
Default ms access - assigning pk via sql query

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, 08:26 PM
Trevor Best
Guest
 
Posts: n/a
Default 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, 08:27 PM
Alan Webb
Guest
 
Posts: n/a
Default 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, 08:27 PM
Trevor Best
Guest
 
Posts: n/a
Default 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?
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,840 network members.