[Solved] Unique Constraint - What Does It Mean?

Creating tables and queries
Post Reply
User avatar
LJ Bettona
Posts: 58
Joined: Fri Jan 04, 2008 12:31 pm
Location: Italy

[Solved] Unique Constraint - What Does It Mean?

Post by LJ Bettona »

I am following the To Base and Back Again tutorial series from neowiki. In the Establishing Relationships tutorial, the author creates a Unique Constraint using an SQL statement. By blindly following the instructions, I, too, have created a unique constraint. But I don't know why. I understand a Unique Index.

What does a Unique Constraint do? Why would I want to create one? I have checked the index in SQL for Mortals and it ain't even there, so that's no help.

I searched this part of the forum and although there is one solved post on the subject, the answer doesn't clarify the Why?, only the How?.

Can someone explain the rationale behind Unique Constraint, please? I know I won't die if I don't find out, but I'm sure it'll save me tearing my hair out further down the line.
Thanks
Last edited by LJ Bettona on Sun Mar 02, 2008 1:04 pm, edited 1 time in total.
iMac G5, OS 10.4.11
OO 2.4, NeoOffice 3 patch 1
OOo 2.2.X on Mac OSx other + Actually NeoOffice 3 patch 1
User avatar
DrewJensen
Volunteer
Posts: 1734
Joined: Sat Oct 06, 2007 9:01 pm
Location: Cumberland, MD - USA

Re: Unique Constraint - What Does It Mean?

Post by DrewJensen »

A unique constraint simply says that every value in that column must be unique.

The most common use of this is when declaring a Primary Key on a table - the key is used to uniquely identify one row of data from all other rows of data. It is possible however and sometimes done to have a unique constraint that is not part of the primary key. One reason to do this is that for most database engine once a column has been designated a primary key it can not be altered, whereas if it simply has a unique constraint the constraint can be removed and the column altered.

One item that is Base specific is that any table that will be updated using GUI data controls must have a primary key.

For all database engines, Base's included, designating a column or columns as the primary key automatically creates a unique constraint - without you needing to do anything further.
Former member of The Document Foundation
Former member of Apache OpenOffice PMC
LibreOffice on Ubuntu 18.04
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Unique Constraint - What Does It Mean?

Post by Villeroy »

DrewJensen wrote:One item that is Base specific is that any table that will be updated using GUI data controls must have a primary key.
Except for dBase tables? Bibliography.biblio has no primary key and I can update, insert and delete by any means.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
User avatar
DrewJensen
Volunteer
Posts: 1734
Joined: Sat Oct 06, 2007 9:01 pm
Location: Cumberland, MD - USA

Re: Unique Constraint - What Does It Mean?

Post by DrewJensen »

REALLY news to me...but much is..- that should be changed to conform dont you tink...LOL...

 Edit: Well what do you know...you're right...hmmm 
Former member of The Document Foundation
Former member of Apache OpenOffice PMC
LibreOffice on Ubuntu 18.04
User avatar
LJ Bettona
Posts: 58
Joined: Fri Jan 04, 2008 12:31 pm
Location: Italy

Re: Unique Constraint - What Does It Mean?

Post by LJ Bettona »

A unique constraint simply says that every value in that column must be unique.
Maybe I missed something somewhere, but I thought that was what a Unique Index did? So, if I want each album title in my CD database to be unique I should put a Unique Constraint on it, not a Unique Index?

Sometimes I ask myself why I couldn't be content with my AppleWorks flat file dbf's? Life was so much simpler then.

Thanks for the responses, guys
iMac G5, OS 10.4.11
OO 2.4, NeoOffice 3 patch 1
OOo 2.2.X on Mac OSx other + Actually NeoOffice 3 patch 1
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Unique Constraint - What Does It Mean?

Post by Villeroy »

Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
User avatar
LJ Bettona
Posts: 58
Joined: Fri Jan 04, 2008 12:31 pm
Location: Italy

Re: Solved Unique Constraint - What Does It Mean?

Post by LJ Bettona »

Thanks for all the help. I'll try to make sense of the wiki article
iMac G5, OS 10.4.11
OO 2.4, NeoOffice 3 patch 1
OOo 2.2.X on Mac OSx other + Actually NeoOffice 3 patch 1
Post Reply