473,654 Members | 3,060 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Unique Index

I have a table listing drawing numbers for jobs. It's primary key combines
Job and numeric part of the drawing number. The structure allows the number
part to repeat for each job.
Job Dwg
6692 001
6692 002
6692 003
6721 001
6721 002

I want add a autonumber primary key. Is there a way in Access97/Jet to
create an index on job / dwg to allow the drawing field to be unique for a
job? I would like to do it at the table level instead of the form.
Aug 14 '06 #1
8 2883
paii, Ron wrote:
I have a table listing drawing numbers for jobs. It's primary key
combines Job and numeric part of the drawing number. The structure
allows the number part to repeat for each job.
Job Dwg
6692 001
6692 002
6692 003
6721 001
6721 002

I want add a autonumber primary key. Is there a way in Access97/Jet to
create an index on job / dwg to allow the drawing field to be unique
for a job? I would like to do it at the table level instead of the
form.
No, not if you want the Dwg number to start over per Job. You could assign
that number in the code event of a form though. I would use the
BeforeUpdate event.

If Me.NewRecord Then
Me.Dwg = Nz(DMax("Dwg", "TableName" , "Job = " & Me!Job), 0) + 1
End If

--
Rick Brandt, Microsoft Access MVP
Email (as appropriate) to...
RBrandt at Hunter dot com
Aug 14 '06 #2

"Rick Brandt" <ri*********@ho tmail.comwrote in message
news:rL******** **********@news svr11.news.prod igy.com...
paii, Ron wrote:
I have a table listing drawing numbers for jobs. It's primary key
combines Job and numeric part of the drawing number. The structure
allows the number part to repeat for each job.
Job Dwg
6692 001
6692 002
6692 003
6721 001
6721 002

I want add a autonumber primary key. Is there a way in Access97/Jet to
create an index on job / dwg to allow the drawing field to be unique
for a job? I would like to do it at the table level instead of the
form.

No, not if you want the Dwg number to start over per Job. You could
assign
that number in the code event of a form though. I would use the
BeforeUpdate event.

If Me.NewRecord Then
Me.Dwg = Nz(DMax("Dwg", "TableName" , "Job = " & Me!Job), 0) + 1
End If

--
Rick Brandt, Microsoft Access MVP
Email (as appropriate) to...
RBrandt at Hunter dot com

That is what I thought, using the Access GUI. I was hoping for a SQL command
that would create the index.

Thank for your reply.
Aug 14 '06 #3
paii, Ron wrote:
I have a table listing drawing numbers for jobs. It's primary key combines
Job and numeric part of the drawing number. The structure allows the number
part to repeat for each job.
Job Dwg
6692 001
6692 002
6692 003
6721 001
6721 002

I want add a autonumber primary key. Is there a way in Access97/Jet to
create an index on job / dwg to allow the drawing field to be unique for a
job? I would like to do it at the table level instead of the form.

Not sure if I'm missing your intent, but you can check out my recent
reply regarding multi-column indexes here:

http://tinyurl.com/sxrok

Please don't fail to read Arvin Meyer's response to same.

Also, consider that your table structure is not normalized. If "jobs"
have "drawings" then this is a hint that these entities should be in
separate tables.

--
Smartin
Aug 15 '06 #4
"paii, Ron" <pa**@packairin c.comwrote in message
<Wv************ *************** ***@athenet.net >:
"Rick Brandt" <ri*********@ho tmail.comwrote in message
news:rL******** **********@news svr11.news.prod igy.com...
>paii, Ron wrote:
>>I have a table listing drawing numbers for jobs. It's primary key
combines Job and numeric part of the drawing number. The structure
allows the number part to repeat for each job.
Job Dwg
6692 001
6692 002
6692 003
6721 001
6721 002

I want add a autonumber primary key. Is there a way in Access97/Jet
to create an index on job / dwg to allow the drawing field to be
unique for a job? I would like to do it at the table level instead
of the form.

No, not if you want the Dwg number to start over per Job. You could
assign that number in the code event of a form though. I would use
the BeforeUpdate event.

If Me.NewRecord Then
Me.Dwg = Nz(DMax("Dwg", "TableName" , "Job = " & Me!Job), 0) + 1
End If

--
Rick Brandt, Microsoft Access MVP
Email (as appropriate) to...
RBrandt at Hunter dot com


That is what I thought, using the Access GUI. I was hoping for a SQL
command that would create the index.

Thank for your reply.
I think you can create the index through DDL, but that's the means of
ensuring data integrity, not how to populate it. So, if the two fields
are the current compound primary key, and you wish those to become a
compound index and add an autonumber field to the table to be primary
key, I think something like the following air code might perhaps be of
assistance

dim db as dao.database
set db = dbengine(0)(0)
db.execute "DROP INDEX PrimaryKey ON table1"
' PrimaryKey - the name of the primary key index
db.execute "ALTER TABLE table1 ADD COLUMN id Counter"
db.execute "CREATE INDEX PrimaryKey ON table1 (id) WITH PRIMARY"
db.execute "CREATE UNIQUE INDEX idxJobDwg ON table1 (Job, Dwg) " & _
"WITH DISALLOW NULL"
set db = nothing

--
Roy-Vidar
Aug 15 '06 #5

"Smartin" <sm********@yah oo.comwrote in message
news:Qb******** *************** *******@giganew s.com...
paii, Ron wrote:
I have a table listing drawing numbers for jobs. It's primary key
combines
Job and numeric part of the drawing number. The structure allows the
number
part to repeat for each job.
Job Dwg
6692 001
6692 002
6692 003
6721 001
6721 002

I want add a autonumber primary key. Is there a way in Access97/Jet to
create an index on job / dwg to allow the drawing field to be unique for
a
job? I would like to do it at the table level instead of the form.

Not sure if I'm missing your intent, but you can check out my recent
reply regarding multi-column indexes here:

http://tinyurl.com/sxrok

Please don't fail to read Arvin Meyer's response to same.

Also, consider that your table structure is not normalized. If "jobs"
have "drawings" then this is a hint that these entities should be in
separate tables.

--
Smartin
Job is a Foreign Key in this table, and primary in the "Jobs" table.
Combining [Job], [Dwg] and one other field creates a file name. I broke it
up to allow quick lookup of job drawings. And used [Job],[Dwg] as the
primary key to keep users from duplicating the [Dwg] part when creating new
drawing files, for the job. If I add a 3rd field to the primary index, [Dwg]
is no longer guaranteed unique unless I add code to the form.
Aug 15 '06 #6

"RoyVidar" <ro************ *@yahoo.nowrote in message
news:mn******** *************** @yahoo.no...
"paii, Ron" <pa**@packairin c.comwrote in message
<Wv************ *************** ***@athenet.net >:
"Rick Brandt" <ri*********@ho tmail.comwrote in message
news:rL******** **********@news svr11.news.prod igy.com...
paii, Ron wrote:
I have a table listing drawing numbers for jobs. It's primary key
combines Job and numeric part of the drawing number. The structure
allows the number part to repeat for each job.
Job Dwg
6692 001
6692 002
6692 003
6721 001
6721 002

I want add a autonumber primary key. Is there a way in Access97/Jet
to create an index on job / dwg to allow the drawing field to be
unique for a job? I would like to do it at the table level instead
of the form.

No, not if you want the Dwg number to start over per Job. You could
assign that number in the code event of a form though. I would use
the BeforeUpdate event.

If Me.NewRecord Then
Me.Dwg = Nz(DMax("Dwg", "TableName" , "Job = " & Me!Job), 0) + 1
End If

--
Rick Brandt, Microsoft Access MVP
Email (as appropriate) to...
RBrandt at Hunter dot com

That is what I thought, using the Access GUI. I was hoping for a SQL
command that would create the index.

Thank for your reply.

I think you can create the index through DDL, but that's the means of
ensuring data integrity, not how to populate it. So, if the two fields
are the current compound primary key, and you wish those to become a
compound index and add an autonumber field to the table to be primary
key, I think something like the following air code might perhaps be of
assistance

dim db as dao.database
set db = dbengine(0)(0)
db.execute "DROP INDEX PrimaryKey ON table1"
' PrimaryKey - the name of the primary key index
db.execute "ALTER TABLE table1 ADD COLUMN id Counter"
db.execute "CREATE INDEX PrimaryKey ON table1 (id) WITH PRIMARY"
db.execute "CREATE UNIQUE INDEX idxJobDwg ON table1 (Job, Dwg) " & _
"WITH DISALLOW NULL"
set db = nothing

--
Roy-Vidar

I will give that code a try. Will the new key show in the GUI or will I need
to document.
Aug 15 '06 #7

"RoyVidar" <ro************ *@yahoo.nowrote in message
news:mn******** *************** @yahoo.no...
"paii, Ron" <pa**@packairin c.comwrote in message
<Wv************ *************** ***@athenet.net >:
"Rick Brandt" <ri*********@ho tmail.comwrote in message
news:rL******** **********@news svr11.news.prod igy.com...
paii, Ron wrote:
I have a table listing drawing numbers for jobs. It's primary key
combines Job and numeric part of the drawing number. The structure
allows the number part to repeat for each job.
Job Dwg
6692 001
6692 002
6692 003
6721 001
6721 002

I want add a autonumber primary key. Is there a way in Access97/Jet
to create an index on job / dwg to allow the drawing field to be
unique for a job? I would like to do it at the table level instead
of the form.

No, not if you want the Dwg number to start over per Job. You could
assign that number in the code event of a form though. I would use
the BeforeUpdate event.

If Me.NewRecord Then
Me.Dwg = Nz(DMax("Dwg", "TableName" , "Job = " & Me!Job), 0) + 1
End If

--
Rick Brandt, Microsoft Access MVP
Email (as appropriate) to...
RBrandt at Hunter dot com

That is what I thought, using the Access GUI. I was hoping for a SQL
command that would create the index.

Thank for your reply.

I think you can create the index through DDL, but that's the means of
ensuring data integrity, not how to populate it. So, if the two fields
are the current compound primary key, and you wish those to become a
compound index and add an autonumber field to the table to be primary
key, I think something like the following air code might perhaps be of
assistance

dim db as dao.database
set db = dbengine(0)(0)
db.execute "DROP INDEX PrimaryKey ON table1"
' PrimaryKey - the name of the primary key index
db.execute "ALTER TABLE table1 ADD COLUMN id Counter"
db.execute "CREATE INDEX PrimaryKey ON table1 (id) WITH PRIMARY"
db.execute "CREATE UNIQUE INDEX idxJobDwg ON table1 (Job, Dwg) " & _
"WITH DISALLOW NULL"
set db = nothing

--
Roy-Vidar

Thank you, It work perfect. It was doable in the GUI, once I saw what your
code created.
Aug 15 '06 #8

"Smartin" <sm********@yah oo.comwrote in message
news:Qb******** *************** *******@giganew s.com...
paii, Ron wrote:
I have a table listing drawing numbers for jobs. It's primary key
combines
Job and numeric part of the drawing number. The structure allows the
number
part to repeat for each job.
Job Dwg
6692 001
6692 002
6692 003
6721 001
6721 002

I want add a autonumber primary key. Is there a way in Access97/Jet to
create an index on job / dwg to allow the drawing field to be unique for
a
job? I would like to do it at the table level instead of the form.

Not sure if I'm missing your intent, but you can check out my recent
reply regarding multi-column indexes here:

http://tinyurl.com/sxrok

Please don't fail to read Arvin Meyer's response to same.

Also, consider that your table structure is not normalized. If "jobs"
have "drawings" then this is a hint that these entities should be in
separate tables.

--
Smartin
I reread your post and applied the code from RoyVidar. It turns out I was
trying to do as you recommended, but until today did not know how to create
a unique index on multiple fields that were not a primary key. The original
table structure work ok until I needed to reference it in another
application, where the multiple field user edited primary key would cause
problems.

Thank you for your help.
Aug 15 '06 #9

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

Similar topics

5
602
by: Laphan | last post by:
Hi All I know you can set a row to be unique, but I want expand on this in that I want the DB schema to only disallow an entry if the row isn't unique across 3 fields. Is it possible? My DDL for this table is as follows: CREATE TABLE `WEBSTRINGS` ( `STRINGID` INT NOT NULL AUTO_INCREMENT,
3
27464
by: June Moore | last post by:
Hi, I would like to add a unique index that consists of two fields in a table. e.g. tbl_A (field1,field2) -- field1 & field2 Indexed and combination must be Unique. Can anyone tell me the actual sql syntax to create this index? Thanks, June.
5
10867
by: Kamil | last post by:
Hello What should I use for better perfomance since unique constraint always use index ? Thanks Kamil
9
2425
by: Rolf Kemper | last post by:
Dear Experts, I got stuck with the following problem and need your help. What I wnat to do is to get a set of distinct nodes. Before the distinct I have selected the multiple occourences already sucsessfully. However , the rest does not work as expected. Hope someone can help on that. Rolf
6
2090
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
16716
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:
10
14671
by: Laurence | last post by:
Hi there, How to differentiate between unique constraint and unique index? These are very similar but I cannot differentiate them? Could someone give me a hand? Thanks in advance
3
35380
by: vj_dba | last post by:
Hi Group, I have a Primary key in my table. It's clear Primary key wont allow duplicates, this primary key creates one index for retrival. Suppose if my table is having a Unique index also. Then what is the exact difference between the Primary key and the Unique index? Also which on data retrival..internally it uses the Primary key index
4
5173
by: p175 | last post by:
What are the advantages / disadvantages of having primary keys in lieu of ordinary indexes ? If there are no foreign relationships defined, is it better to have a two column index allowing reverse scans or primary key ? Any performance or other benefits / issues ? Many thanks.
6
4315
by: Alvin SIU | last post by:
Hi all, I have a table in Db2 v8 like this: Team Name Role ------ -------- --------------------- A Superman Leader A Batman Member A WonderWoman Member B Alvin Leader
0
8379
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8294
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
8816
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8494
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,...
1
6162
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
5627
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();...
1
2719
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1924
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1597
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.