Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 1020 Vote(s) - 3.55 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Can I have multiple primary keys in a single table?

#11
A Table can have a **Composite Primary Key** which is a primary key made from two or more columns. For example:

CREATE TABLE userdata (
userid INT,
userdataid INT,
info char(200),
primary key (userid, userdataid)
);


**Update:** [Here is a link][1] with a more detailed description of composite primary keys.


[1]:

[To see links please register here]

Reply

#12
Having two primary keys at the same time, is not possible. But (assuming that you have not messed the case up with composite key), may be what you might need is to make one attribute unique.

CREATE t1(
c1 int NOT NULL,
c2 int NOT NULL UNIQUE,
...,
PRIMARY KEY (c1)
);

However note that in relational database a 'super key' is a subset of attributes which uniquely identify a tuple or row in a table. A 'key' is a 'super key' that has an additional property that removing any attribute from the key, makes that key no more a 'super key'(or simply a 'key' is a minimal super key). If there are more keys, all of them are candidate keys. We select one of the candidate keys as a primary key. That's why talking about multiple primary keys for a one relation or table is being a conflict.
Reply

#13
(Have been studying these, a lot)

**Candidate keys** - A minimal column combination required to uniquely identify a table row.
**Compound keys** - 2 or more columns.

- Multiple **Candidate keys** can exist in a table.
- **Primary KEY** - Only one of the candidate keys that is *chosen* by us
- **Alternate keys** - All *other* candidate keys
- Both Primary Key & Alternate keys can be **Compound keys**

Sources:

[To see links please register here]

[To see links please register here]

[To see links please register here]

[To see links please register here]

Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through