Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the name of the primary-key from a query

Tags:

sybase

sap-ase

I am searching for a query that tell me the NAME of the primary-key of a table
example: In oracle I do this

select CONSTRAINT_NAME from user_constraints where table_name = 'CT' AND CONSTRAINT_TYPE ='P'

how to do that in sybase ?

like image 437
Moudiz Avatar asked Jun 17 '13 08:06

Moudiz


People also ask

What is the name of the primary key?

A primary key, also called a primary keyword, is a column in a relational database table that's distinctive for each record. It's a unique identifier, such as a driver's license number, telephone number with area code or vehicle identification number (VIN). A relational database must have only one primary key.

How do you reference a primary key in SQL?

SQL PRIMARY KEY on ALTER TABLE. ADD CONSTRAINT PK_Person PRIMARY KEY (ID,LastName); Note: If you use ALTER TABLE to add a primary key, the primary key column(s) must have been declared to not contain NULL values (when the table was first created).

How do I find the hostname of a SQL query?

Use MachineName property to get the computer name on which the SQL Server instance is running. For a cluster, it returns the virtual server name. Select SERVERPROPERTY('MachineName') as 'MachineName'.


1 Answers

Try this way:

select name     
from sysindexes
where indid > 0
and status2 & 2 = 2
like image 96
Robert Avatar answered Sep 21 '22 11:09

Robert