473,804 Members | 3,194 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

difference between Primary and Unique index?

I have a Make Table query that creates a fairly large table. The Make Table
query populates the new table with one AutoNumber field (which is taken form
another unrelated table as part of the query).

I want to make the AutoNumber field the Primary Key:

DoCmd.OpenQuery "qryXL_To" ' this is the make table query
DoCmd.RunSQL "CREATE UNIQUE INDEX idxTxAcct ON tblXL_To (TxAcct_ID)"

This seems to work okay, but it does not create a "Primary" key -- do I need
a primary key?

Also, why do I need to name the Index -- when I create a table manually,
I've never had to name the Index/Primary Key...

thanks in advance!
Nov 12 '05 #1
4 14428
DJ -

Well here is the syntax per Access 97 Help:

CREATE [ UNIQUE ] INDEX index
ON table (field [ASC|DESC][, field [ASC|DESC], ...])
[WITH { PRIMARY | DISALLOW NULL | IGNORE NULL }]

and....

'Designate the indexed field or fields as the primary key by using the
PRIMARY reserved word. This implies that the key is unique, so you can
omit the UNIQUE reserved word.'

I think that when you create a table in design mode the default name for
the PK is PrimaryKey. But for all other indexes you have to supply a
name. And the PK doesn't have to be called 'PrimaryKey'.

Just my $0.02 worth...

- Brian

In article <nu************ *****@newssvr29 .news.prodigy.c om>,
dj****@hotmail. com says...
I have a Make Table query that creates a fairly large table. The Make Table
query populates the new table with one AutoNumber field (which is taken form
another unrelated table as part of the query).

I want to make the AutoNumber field the Primary Key:

DoCmd.OpenQuery "qryXL_To" ' this is the make table query
DoCmd.RunSQL "CREATE UNIQUE INDEX idxTxAcct ON tblXL_To (TxAcct_ID)"

This seems to work okay, but it does not create a "Primary" key -- do I need
a primary key?

Also, why do I need to name the Index -- when I create a table manually,
I've never had to name the Index/Primary Key...

thanks in advance!

--
Remove NOSPAM to reply...
Nov 12 '05 #2
This seems to work:

DoCmd.RunSQL "CREATE UNIQUE INDEX idxTxID ON tblXL_Tx (Tx_ID) WITH
PRIMARY"

The reason I was having trouble is because I did not include a name for the
index.

"deko" <dj****@hotmail .com> wrote in message
news:nu******** *********@newss vr29.news.prodi gy.com...
I have a Make Table query that creates a fairly large table. The Make Table query populates the new table with one AutoNumber field (which is taken form another unrelated table as part of the query).

I want to make the AutoNumber field the Primary Key:

DoCmd.OpenQuery "qryXL_To" ' this is the make table query
DoCmd.RunSQL "CREATE UNIQUE INDEX idxTxAcct ON tblXL_To (TxAcct_ID)"

This seems to work okay, but it does not create a "Primary" key -- do I need a primary key?

Also, why do I need to name the Index -- when I create a table manually,
I've never had to name the Index/Primary Key...

thanks in advance!

Nov 12 '05 #3
A primary Key does not allow nulls, a unique indes will allow one null
value.
Every object has to have a name. When you use the user interface,
Access generates a random name on your behalf for the index .

A table can have one and only one primary key (which could be composite key
combining several columns) , but as many unique indexes as you need
Although unique keys can and are sometimes used to identify a row
(individual records), it is the
primary key that is predominantly used to identify a row.

Explicitly providing an index name can be done only through code, and can be
advantageous
because you can now address that index specifically - for example you could
say
drop index (myIndex), instead of iterating thtough collections etc.

HS
"deko" <dj****@hotmail .com> wrote in message
news:nu******** *********@newss vr29.news.prodi gy.com...
I have a Make Table query that creates a fairly large table. The Make Table query populates the new table with one AutoNumber field (which is taken form another unrelated table as part of the query).

I want to make the AutoNumber field the Primary Key:

DoCmd.OpenQuery "qryXL_To" ' this is the make table query
DoCmd.RunSQL "CREATE UNIQUE INDEX idxTxAcct ON tblXL_To (TxAcct_ID)"

This seems to work okay, but it does not create a "Primary" key -- do I need a primary key?

Also, why do I need to name the Index -- when I create a table manually,
I've never had to name the Index/Primary Key...

thanks in advance!

Nov 12 '05 #4
I've discovered the make table query and will be setting a lot of PK's...
thanks for the helpful explanation!

"HSalim" <On************ ******@msn.com> wrote in message
news:h5******** **********@nwrd ny02.gnilink.ne t...
A primary Key does not allow nulls, a unique indes will allow one null
value.
Every object has to have a name. When you use the user interface,
Access generates a random name on your behalf for the index .

A table can have one and only one primary key (which could be composite key combining several columns) , but as many unique indexes as you need
Although unique keys can and are sometimes used to identify a row
(individual records), it is the
primary key that is predominantly used to identify a row.

Explicitly providing an index name can be done only through code, and can be advantageous
because you can now address that index specifically - for example you could say
drop index (myIndex), instead of iterating thtough collections etc.

HS
"deko" <dj****@hotmail .com> wrote in message
news:nu******** *********@newss vr29.news.prodi gy.com...
I have a Make Table query that creates a fairly large table. The Make

Table
query populates the new table with one AutoNumber field (which is taken

form
another unrelated table as part of the query).

I want to make the AutoNumber field the Primary Key:

DoCmd.OpenQuery "qryXL_To" ' this is the make table query
DoCmd.RunSQL "CREATE UNIQUE INDEX idxTxAcct ON tblXL_To (TxAcct_ID)"

This seems to work okay, but it does not create a "Primary" key -- do I

need
a primary key?

Also, why do I need to name the Index -- when I create a table manually,
I've never had to name the Index/Primary Key...

thanks in advance!


Nov 12 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
8133
by: Westcoast Sheri | last post by:
Which will be a faster lookup of an item by, "color" in the following mySQL tables: "unique key," "primary key," or just plain "key"?? CREATE TABLE myTable ( number int(11) NOT NULL default '0', description varchar(50) NOT NULL default '', color varchar(30) NOT NULL default '', price decimal(3,2) NOT NULL default '0.00', UNIQUE KEY (color) );
4
25155
by: Peter Scott | last post by:
I created a table that has a column in that needs to contain a full Unix file path. Since 2048 was too long for a VARCHAR, I made it TEXT. I since populated the table. Now I want to make the path column a primary key, and I can't figure out how. (I googled the web and groups without luck, looked over the reference manual also, especially reading the entry on BLOBs.) I was able to make a fulltext index with: create fulltext index...
4
2883
by: Q. John Chen | last post by:
All, What's the difference between a unique contraint and unique? sementically, if you want a column contain unique values, it is a contraint. And an index is for searching/sort. The questions are: 1. Does a unique constraint interally use unique index? 2. If Yes to #1, I DO NOT need to create an index for search/sort purpose, right?
1
5748
by: Raquel | last post by:
Here is the scenario: 1. I create a unique index on a table. 2. I create a primary key on that table with same columns as the ones in the unique index by Alter table add primary key statement. The primary key defined 'uses' the unique index created in step 1 to enfore uniqueness. 3. I drop the primary key. (Alter table drop primary key). After step 3:
6
2100
by: Bob Stearns | last post by:
I was under the impression that the primary key had to be a unique index. Since I usually create my primary indices before my primary keys, in order to get the indices in the same schema as their tables, it is possible , by error, to create such an index without the unique attribute. DB2 UDB 8.1.5 Linux uses such an index for the primary key anyway, thus losing the unique property of the primary key. Is this a bug or a feature, i.e. a...
5
16738
by: aj | last post by:
DB2 WSE 8.1 FP5 Red Hat AS 2.1 What is the difference between adding a unique constraint like: ALTER TABLE <SCHEMA>.<TABLE> ADD CONSTRAINT CC1131378283225 UNIQUE ( <COL1>) ; and adding a unique index like:
8
31547
by: Paul Hunter | last post by:
I am new to databases and thus to Access. I have a situation where I am trying to figure out how to key some tables I am working with. Consider that I have a database of my own records which are invoices I work on. These invoices are from four companies with their own invoice numbers. So, I cannot key by invoice number because there is a likelihood of invoice numbers duplicated by different companies. The records in this table of joined...
115
6282
by: LurfysMa | last post by:
Most of the reference books recommend autonum primary keys, but the Access help says that any unique keys will work. What are the tradeoffs? I have several tables that have unique fields. Can I use them as primary keys or should I define an autonum primary key? One table has information about the 50 states in the US. The table looks like this:
1
5362
by: mark_aok | last post by:
Hi all, I have a situation where I need to determine a specific table's primary key, and then output it. I have tried the Database Object, and the Record Object, but I've had no luck. Ideally there would be something like,
0
9579
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10332
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10321
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9152
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7620
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6853
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5522
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3820
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2991
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.