File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
Win a copy of
Meteor in Action
this week in the
JDBC and Relational Databases
SQL check constraint
Joined: Nov 18, 2003
Jun 11, 2006 03:42:00
It is only about SQL (DDL) and to be more specific - about PostgreSQL.
I have to create a table coordinates with rows: x integer, y integer, id integer, data_set integer. And I allso must specify that in one data_set, there is no dublicated set of coordinates.
My first attempt was like that:
CREATE TABLE coordinates ( x INTEGER NOT NULL, y INTEGER NOT NULL, coordinates_ID INTEGER NOT NULL, data_set_ID INTEGER NOT NULL, CONSTRAINT PK_coordinates1 PRIMARY KEY (coordinates_ID), [B]UNIQUE (x, y)[/B] );
But this one fails, because it does not care about data_set_ID.
So if there is any SQL guru out there, help is very welcome. How would you complete this, or what would you add to the code above?
CREATE TABLE coordinates ( x INTEGER NOT NULL, y INTEGER NOT NULL, coordinates_ID INTEGER NOT NULL, data_set_ID INTEGER NOT NULL, CONSTRAINT PK_coordinates1 PRIMARY KEY (coordinates_ID), CONSTRAINT chk_coordinates1 CHECK ... );
[ June 11, 2006: Message edited by: Juhan Voolaid ]
Joined: Nov 18, 2003
Jun 11, 2006 04:38:00
The solution is more simple than I could excpect in my wildest dreams:
UNIQUE (x, y, data_set_id)
author & internet detective
Joined: May 26, 2003
Jun 11, 2006 08:22:00
Thanks for posting the solution for others who see this thread in the future.
OCA 8 book
How To Ask Questions The Smart Way
Blogging on Certs:
SCEA Part 1
Part 2 & 3
Core Spring 3
TOGAF part 1
I agree. Here's the link:
subject: SQL check constraint
Syntax error for Access Database
Hibernate: Found two representations of same collection
Multiple columns having same foreign key
Hibernate mapping doubt
Displaying Dynamic Nested Menu in JSP
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2015