How do I discover a table's primary key?
- From: jbrock@xxxxxxxxx (John Brock)
- Date: Fri, 16 Jun 2006 19:26:46 +0000 (UTC)
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
.
- Follow-Ups:
- Re: How do I discover a table's primary key?
- From: Mark A. Parsons
- Re: How do I discover a table's primary key?
- Prev by Date: Re: using clustered index to optimize inserts ...
- Next by Date: Re: How do I discover a table's primary key?
- Previous by thread: Sybase DBA group in Yahoo.
- Next by thread: Re: How do I discover a table's primary key?
- Index(es):
Relevant Pages
|
|