473,385 Members | 1,764 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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

Nov 12 '05 #1
3 2173
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Mats | last post by:
It's good practice to validate input, not only where it should be coming from, but from anywhere it's possible to change or add input for a "client". If all user input is transfered using "post"...
29
by: Mark B | last post by:
We have an Access app (quite big) at www.orbisoft.com/download. We have had requests by potential users to have it converted to an SQL version for them since there corporate policy excludes them...
2
by: StaZ | last post by:
Hello, I would simply like to know if there's a way to disable the "feature" of MS Access that rewrites your queries "correctly"... This feature makes this : ...WHERE SomeBooleanField...;...
3
by: Andy Davis | last post by:
I have set up a mail merge document in Word 2003 which gets its data from my Access 2000 database. I want to set up a button on a form that: 1. runs the query to provide the dat for the merge...
7
by: manning_news | last post by:
I've got a report that's not sorting correctly. I build a SQL statement and assign it to the recordsource in the Open event, sorting the data the way the user chooses. The user can choose up to 3...
1
by: JH | last post by:
I have a comma delimited file and I want to export it to an MS access table already designed with appropriate field names. How do I do this programmatically using VB.NET or C#? Thanks for any...
1
by: puiatti | last post by:
Hi Guys, Any help offered on the below 2 queries (mind the pun) is gratefully received. 1) I'm constucting a db of betting results data. Each bet as a whole is called a "position" and every...
6
by: jsacrey | last post by:
Hello everybody, I've got a bit of a situation that I could use some guidance with if possible. I work for an auditing firm where my users audit electronic shipping data for customers to see if...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.