Difference between revisions of "UNIQUE Table Constraint"

From Recital Documentation Wiki
Jump to: navigation, search
 
(2 intermediate revisions by 2 users not shown)
Line 28: Line 28:
 
==Example==
 
==Example==
 
<code lang="recital">
 
<code lang="recital">
set sql to vfp
+
CREATE TABLE newcust;
CREATE TABLE newcust (acc_ref char(5) default strzero(seqno(),5), acc_name char(20))
+
  (acc_ref char(5) default strzero(seqno(),5),;
ALTER TABLE newcust ADD UNIQUE acc_ref+acc_name TAG RefName
+
  acc_name char(20))
list structure index
+
ALTER TABLE newcust;
 +
  ADD UNIQUE acc_ref+acc_name TAG RefName
  
set sql to mysql
+
CREATE TABLE contact;
CREATE TABLE contact (ContRef char(5), LastName char(25), FirstName char(25),
+
  (ContRef char(5), LastName char(25), FirstName char(25),;
UNIQUE FullName (LastName, FirstName, ContRef));
+
  UNIQUE FullName (LastName, FirstName, ContRef))
 
</code>
 
</code>
  
  
 
==Products==
 
==Products==
Recital Database Server, Recital Mirage Server, Recital Terminal Developer
+
Recital, Recital Server
 
[[Category:Documentation]]
 
[[Category:Documentation]]
 
[[Category:SQL]]
 
[[Category:SQL]]

Latest revision as of 11:16, 22 December 2009

Purpose

Table constraint to define a candidate index


Syntax

UNIQUE <expr> TAG <cTagName> [COLLATE <cCollateSequence>]

UNIQUE [<cTagName>] (column1[column2,…])


See Also

ALTER TABLE, CONSTRAINTS, CREATE TABLE


Description

A constraint is used to define rules that help to provide data integrity. TABLE constraints apply to table-based operations. You must have ALTER privilege on the table. The table will be locked for EXCLUSIVE use during the operation.

UNIQUE <expr> TAG <cTagName> The UNIQUE table constraint is used to define <expr> as a candidate index for the table. The <expr> can contain any valid index key. A unique tag index is built on the specified <expr>; it is given the name as defined in <cTagName>. A table may have more than one candidate index.

COLLATE <cCollateSequence> The optional COLLATE <cCollateSequence> clause is included for Visual FoxPro language compatibility only.

UNIQUE [<cTagName>] (column1[column2,…]) The UNIQUE table constraint is used to define a unique index key. The index is built on the column or columns specified and given the name as defined in <cTagName>.


Example

CREATE TABLE newcust;
  (acc_ref char(5) default strzero(seqno(),5),;
  acc_name char(20))
ALTER TABLE newcust;
  ADD UNIQUE acc_ref+acc_name TAG RefName
 
CREATE TABLE contact;
  (ContRef char(5), LastName char(25), FirstName char(25),;
  UNIQUE FullName (LastName, FirstName, ContRef))


Products

Recital, Recital Server