How do I discover a table's primary key?



I have an existing Sybase database (ASE 12.5) in which every table
is defined with a primary key, e.g.:

create table City (
City varchar(20) not null,
Region varchar(20) not null,
primary key (City)
)

Is there a way to look at the system tables and discover what the
primary key on this table is?

I know that there is an entry in sysindexes. But some tables have
multiple indexes, and it is not clear to me from looking at the
definition of sysindexes that there is any way to pick out which
index enforces the primary key relationship.

I also looked at syskeys, but right now it is essentially empty.
I know that I could populate it using sp_primarykey, but that would
require that I update the code that generates our database definitions
so to generate the appropriate sp_primarykey statements. I can do
that, but if there is a way to get this information from the database
as it currently stands that would be preferable. Is there a way?

I have to say I really don't understand the reasoning behind
sp_primarykey. It seems to me that syskeys should be a read-only
table that is populated automatically when tables and relationships
are created. This would be less work for the database designer,
and would also reduce the possibility of errors (note that
sp_primarykey can be used to define "primary keys" that are completely
nonsensical!). Is there some good reason for doing things this
way, or is sp_primarykey basically a legacy misfeature?
--
John Brock
jbrock@xxxxxxxxx

.



Relevant Pages

  • Re: problem using identity column as primary key
    ... >> I am thinking of creating an identity column to use it as primary key ... More and more programmers who have absolutely no database training are ... the gap in the sequence is not filled in and the sequence ... vin CHARNOT NULL REFERENCES Motorpool); ...
    (microsoft.public.sqlserver.programming)
  • Re: Updating the SQL key value
    ... before creating the database, by the time I've come to pick a primary key, ... articles, each of which must be issued under a particular licence (e.g. ... GPL GNU General Public Licence http://www.gnu ... ...
    (comp.lang.php)
  • Re: Concatenate and Null Values -- Features
    ... Tony Toews dislikes cascade deletes as well as cascade updates, ... fence regarding the use of natural versus surrogate (autonumber) keys. ... Database Normalization Tips ... For optimal database design and performance, the primary key of a table ...
    (microsoft.public.access.reports)
  • Re: simple database
    ... Into what component of the database did you enter over 100 ... The company's Employee ... ID number can be a primary key in that table, ... Possessors, and Transfers are the names he is using. ...
    (microsoft.public.access.gettingstarted)
  • Re: AutoNumber Question
    ... I would like to point out that a primary key does not need to be meaningless ... database, as it would be if it was part of relationships. ... VIN is being reused. ... so a VIN has meaning separate from ...
    (microsoft.public.access.tablesdbdesign)