By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,098 Members | 989 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,098 IT Pros & Developers. It's quick & easy.

ms access - assigning pk via sql query

P: 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

Nov 12 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Bernie Yaeger wrote:
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

ALTER TABLE [TableName] ADD CONSTRAINT
[PrimaryKeyName PRIMARY KEY
(
[PrimaryKeyColumn]
)
--
But why is the Rum gone?
Nov 12 '05 #2

P: n/a
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" <be*****@cherwellinc.com> wrote in message
news:34*********************@news4.srv.hcvlny.cv.n et...
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

Nov 12 '05 #3

P: n/a
Trevor Best wrote:
Bernie Yaeger wrote:
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

ALTER TABLE [TableName] ADD CONSTRAINT
[PrimaryKeyName PRIMARY KEY
(
[PrimaryKeyColumn]
)

Sorry 'nother typo: should be "[PrimaryKeyName]" with a closing square
bracket.

--
But why is the Rum gone?
Nov 12 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.