Question

I'm not certain how to title this question, but here's my question. I'm new to Databasing so this might be simple, but no one I've asked has a clue how to do it.

Is there a rule I can write in an access database that will link 3 entries to equal one unique value?

CREATE TABLE x(
_a_ int,
_b_ varchar(255),
_y_ int,
_z_ varchar(255)
); 

i.e. the above table, I wish a, b, and y to be unique when looked at together, but each individual entry can be set non-uniquely. How would I go about linking tables with a rule like this when only one entry is present, or should I rewrite the tables to reflect this change?

I'm writing this code in VB.NET to access the database, I'm editing the database using access, and I have VS2012. I've been using OleDb to access the DB, but I suppose that's all mostly irrelavent since I'm asking about the database settings and SQL statements/rules as opposed to the programming.

Was it helpful?

Solution

Try adding a CONSTRAINT:

CREATE TABLE x(
  _a_ int,
  _b_ varchar(255),
  _y_ int,
  _z_ varchar(255),
CONSTRAINT pk_Keys PRIMARY KEY (_a_, _b_, _y_)
);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top