dbTalk Databases Forums  

Create Table with multi-column constraint(unique)

comp.databases.ms-access comp.databases.ms-access


Discuss Create Table with multi-column constraint(unique) in the comp.databases.ms-access forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Ron
 
Posts: n/a

Default Create Table with multi-column constraint(unique) - 08-01-2010 , 11:02 AM






Hi.
a couple of questions about creating an access (2007) table with a
multi-column unique constraint.
I know how do the above using an SQL statement within the access program.
i.e.
CREATE TABLE testTBL
(
myID int NOT NULL
myLastName varchar(25) NOT NULL
myOtherField1 int
myOtherField2 int
CONSTRAINT my2FieldsUniqueConstraint UNIQUE (myID, myLastName)
)

question 1... using access 2007 and when in table DESIGN VIEW mode... can
you create the same type table as above (without using an SQL statement)?

question 2... after creating the table above successfully, how can you tell
that it has the two field unique constraint on the table. I checked the
fields properties info section of the two constrained fields and I don't see
anything that would tell me about the Unique two field constraint. Of
course if you try and enter the same data in these two fields on two
different rows you get an error (as expected) but is there some way of
showing the table schema which will tell me this info in case I forgot that
the table was originally created with the unique constraint across the two
fields?

TIA
Ron

Reply With Quote
  #2  
Old   
Marshall Barton
 
Posts: n/a

Default Re: Create Table with multi-column constraint(unique) - 08-01-2010 , 02:34 PM






Ron wrote:
Quote:
a couple of questions about creating an access (2007) table with a
multi-column unique constraint.
I know how do the above using an SQL statement within the access program.
i.e.
CREATE TABLE testTBL
(
myID int NOT NULL
myLastName varchar(25) NOT NULL
myOtherField1 int
myOtherField2 int
CONSTRAINT my2FieldsUniqueConstraint UNIQUE (myID, myLastName)
)

question 1... using access 2007 and when in table DESIGN VIEW mode... can
you create the same type table as above (without using an SQL statement)?

question 2... after creating the table above successfully, how can you tell
that it has the two field unique constraint on the table. I checked the
fields properties info section of the two constrained fields and I don't see
anything that would tell me about the Unique two field constraint. Of
course if you try and enter the same data in these two fields on two
different rows you get an error (as expected) but is there some way of
showing the table schema which will tell me this info in case I forgot that
the table was originally created with the unique constraint across the two
fields?
Index information is not a property of a field. An index
does have a Fields collection, so you were looking at a 1 to
Many type structure the wrong way around. Look at the
table's Indexes window to see the indexes you set using the
table's design UI. The Indexes window does not display the
indexes that were automatically created via enforced
referential intrigrity in the Relationships window.

Using DAO, you can get to the TableDef object's Indexes
property that is the table's collection of indexes
(Constraints). Then you can check each index's Fields
collection to see which fields and their properties make up
the index. (I've never tried it, but I suppose there is a
way to do something similar using ADOX.) It is a good idea
to keep a routine that does that around so you can check if
you have duplicate indexes as you approch the limit on the
number of constraints.

--
Marsh

Reply With Quote
  #3  
Old   
Phil
 
Posts: n/a

Default Re: Create Table with multi-column constraint(unique) - 08-01-2010 , 04:06 PM



On 01/08/2010 20:34:39, Marshall Barton wrote:
Quote:
Ron wrote:
a couple of questions about creating an access (2007) table with a
multi-column unique constraint.
I know how do the above using an SQL statement within the access program.
i.e.
CREATE TABLE testTBL
(
myID int NOT NULL
myLastName varchar(25) NOT NULL
myOtherField1 int
myOtherField2 int
CONSTRAINT my2FieldsUniqueConstraint UNIQUE (myID, myLastName)
)

question 1... using access 2007 and when in table DESIGN VIEW mode... can
you create the same type table as above (without using an SQL statement)?

question 2... after creating the table above successfully, how can you tell
that it has the two field unique constraint on the table. I checked the
fields properties info section of the two constrained fields and I don't see
anything that would tell me about the Unique two field constraint. Of
course if you try and enter the same data in these two fields on two
different rows you get an error (as expected) but is there some way of
showing the table schema which will tell me this info in case I forgot that
the table was originally created with the unique constraint across the two
fields?

Index information is not a property of a field. An index
does have a Fields collection, so you were looking at a 1 to
Many type structure the wrong way around. Look at the
table's Indexes window to see the indexes you set using the
table's design UI. The Indexes window does not display the
indexes that were automatically created via enforced
referential intrigrity in the Relationships window.

Using DAO, you can get to the TableDef object's Indexes
property that is the table's collection of indexes
(Constraints). Then you can check each index's Fields
collection to see which fields and their properties make up
the index. (I've never tried it, but I suppose there is a
way to do something similar using ADOX.) It is a good idea
to keep a routine that does that around so you can check if
you have duplicate indexes as you approch the limit on the
number of constraints.

--
Marsh

I may be missing the point but you can have an index called say IDName
consisting of the 2 fields MyID and MyLastName and make that unique. So you
can have 1 Smith 2 Smith
but not a secon 1 smith

Phil

Reply With Quote
  #4  
Old   
Ron
 
Posts: n/a

Default Re: Create Table with multi-column constraint(unique) - 08-01-2010 , 04:55 PM



Thanks Marsh... got it, missed that Index dialog box that u pointed out.

"Marshall Barton" <marshbarton (AT) wowway (DOT) com> wrote

Quote:
Ron wrote:
a couple of questions about creating an access (2007) table with a
multi-column unique constraint.
I know how do the above using an SQL statement within the access program.
i.e.
CREATE TABLE testTBL
(
myID int NOT NULL
myLastName varchar(25) NOT NULL
myOtherField1 int
myOtherField2 int
CONSTRAINT my2FieldsUniqueConstraint UNIQUE (myID, myLastName)
)

question 1... using access 2007 and when in table DESIGN VIEW mode... can
you create the same type table as above (without using an SQL statement)?

question 2... after creating the table above successfully, how can you
tell
that it has the two field unique constraint on the table. I checked the
fields properties info section of the two constrained fields and I don't
see
anything that would tell me about the Unique two field constraint. Of
course if you try and enter the same data in these two fields on two
different rows you get an error (as expected) but is there some way of
showing the table schema which will tell me this info in case I forgot
that
the table was originally created with the unique constraint across the two
fields?

Index information is not a property of a field. An index
does have a Fields collection, so you were looking at a 1 to
Many type structure the wrong way around. Look at the
table's Indexes window to see the indexes you set using the
table's design UI. The Indexes window does not display the
indexes that were automatically created via enforced
referential intrigrity in the Relationships window.

Using DAO, you can get to the TableDef object's Indexes
property that is the table's collection of indexes
(Constraints). Then you can check each index's Fields
collection to see which fields and their properties make up
the index. (I've never tried it, but I suppose there is a
way to do something similar using ADOX.) It is a good idea
to keep a routine that does that around so you can check if
you have duplicate indexes as you approch the limit on the
number of constraints.

--
Marsh

Reply With Quote
  #5  
Old   
Ron
 
Posts: n/a

Default Re: Create Table with multi-column constraint(unique) - 08-01-2010 , 04:59 PM



"Phil" <phil (AT) stantonfamily (DOT) co.uk> wrote

Quote:
On 01/08/2010 20:34:39, Marshall Barton wrote:
Ron wrote:
a couple of questions about creating an access (2007) table with a
multi-column unique constraint.
I know how do the above using an SQL statement within the access program.
i.e.
CREATE TABLE testTBL
(
myID int NOT NULL
myLastName varchar(25) NOT NULL
myOtherField1 int
myOtherField2 int
CONSTRAINT my2FieldsUniqueConstraint UNIQUE (myID, myLastName)
)

question 1... using access 2007 and when in table DESIGN VIEW mode... can
you create the same type table as above (without using an SQL statement)?

question 2... after creating the table above successfully, how can you
tell
that it has the two field unique constraint on the table. I checked the
fields properties info section of the two constrained fields and I don't
see
anything that would tell me about the Unique two field constraint. Of
course if you try and enter the same data in these two fields on two
different rows you get an error (as expected) but is there some way of
showing the table schema which will tell me this info in case I forgot
that
the table was originally created with the unique constraint across the
two
fields?

I may be missing the point but you can have an index called say IDName
consisting of the 2 fields MyID and MyLastName and make that unique. So
you
can have 1 Smith 2 Smith
but not a secon 1 smith

Phil
Thanks Phil for your response...
my table works like you say and that is the way it was designed, just
wanted to know how to look at the table say 6 months from now and if I
forgot that it had that double field unique index I wanted to know a way to
RE-DISCOVER that fact from within the Access program... Marsh pointed the
way for me....

Reply With Quote
Reply




Thread Tools
Display Modes

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.