0

I am using sybase as I am new to sybase prior to that I have used oracle now I have an database which consists of many table in sybase now there is a table named tarty now can you please advise the command that I can execute in sybase to know is there any primary key is there in tarty table or not .

here i got the solution for this..

select name     
from sysindexes
where indid > 0
and status2 & 2 = 2

Can you also please advise that i want the table name also to be get listed for example the above command will show the primary key only i want the primary key plus the table name also to be listed so that i can know that this primary key belongs to this table please advise what necessary changes i need to do to achieve this..!

Mike Gardner
  • 6,611
  • 5
  • 24
  • 34
asderfgh
  • 123
  • 1
  • 3
  • 9
  • It's helpful to tag your question with the software product and version you are running, or include it in your question. Sybase was a company that produced multiple database products, and not all the syntax is the same. I have added the [sybase-ase] tag to your question, based on the tables you are querying. – Mike Gardner Feb 09 '15 at 14:55

1 Answers1

1

Including the table name is easy:

select name, object_name(id) as table_name
from sysindexes 
where indid > 0
and status2 & 2 = 2

Also see "SQL query to get primary keys for all tables in sybase ase 15.x along with column names" for a related discussion. There's a catalog query sp_pkeys that's included with ASE that you can use or borrow from.

Community
  • 1
  • 1
RobV
  • 2,263
  • 1
  • 11
  • 7