sábado, 22 de noviembre de 2008

BUSCAR CLAVE PRIMARIA DE UNA TABLA

--SOLAMENTE LAS CLAVES PRIMARIAS EN ORDEN.
----------------
--PARA ORACLE
select all_cons_columns.COLUMN_NAME FROM all_constraints, all_cons_columns
where all_constraints.table_name = all_cons_columns.table_name
AND all_constraints.CONSTRAINT_NAME = all_cons_columns.CONSTRAINT_NAME
and all_constraints.table_name='WFA_ANEXOS' and all_constraints.CONSTRAINT_TYPE = 'P'
ORDER BY POSITION


--PARA SQL SERVER

SELECT D.NAME from sysindexes as a, sysobjects as b, sysindexkeys as c, syscolumns as d
where b.id=a.id
and b.type='U'
and c.colid = d.colid
and c.indid = a.indid
and b.id = d.id
and c.id = a.id
--and A.NAME LIKE 'PK_ANEXOS'
and a.name NOT LIKE '_WA%'
and B.name LIKE 'WFA_ANEXOS'
and C.INDID = 1 --PARA LAS CLAVES PRIMARIAS
order by C.KEYNO

Citas y Refranes.com