Conversão para sql server

01/06/2010

Alguem sabe como converter essa instrução do firebird para sql server?
    select b.rdb$field_name as Campo                     
      from rdb$relation_constraints a                    
    inner join rdb$index_segments b                     
    on b.rdb$index_name = a.rdb$index_name
    where a.rdb$constraint_type = 'PRIMARY KEY' and  
    a.rdb$relation_name = :tableName     and exists( select 1 from RDB$RELATION_FIELDS r
                        where r.RDB$RELATION_NAME = a.RDB$RELATION_NAME and
                             ( ( r.RDB$BASE_FIELD = b.rdb$field_name) or ( r.RDB$FIELD_NAME = b.rdb$field_name) ) )) Valeu

Jordelino Santos

Currículo

Respostas

29/07/2010

Fabriciolimadba

  =: isso seria o que no firebird? diferente? Acredito que sua query ficaria assim, faltando alterar o operador que não entendi:
    select b.field_name as Campo                     
      from relation_constraints a                    
    inner join index_segments b                     
    on b.index_name = a.index_name
    where a.constraint_type = 'PRIMARY KEY' and  
    a.relation_name =: tableName     and exists( select 1 from RELATION_FIELDS r
                        where r.RELATION_NAME = a.RELATION_NAME and
                             ( ( r.BASE_FIELD = b.field_name) or ( r.FIELD_NAME = b.field_name) ) ))
Responder Citar

30/07/2010

Emerson

creio que seja:

select
  OBJECT_NAME(OBJECT_ID(N'SA1010')) as Tabela,
  c.name as Campo
from
  sysindexes i
inner join sysobjects o on
  o.id = OBJECT_ID(i.name) and objectproperty(o.id, 'IsPrimaryKey') = 1
inner join sysindexkeys k on
  k.id = i.id and k.indid = i.indid
inner join syscolumns c on
  c.id = i.id and c.colid = k.colid
where
  i.id = OBJECT_ID(N'CLIENTE')


Responder Citar

30/07/2010

Fabriciolimadba

Hum... isso mesmo... pensei que quisesse apenas fazer a query rodar em sql. Não reparei nos nomes das tabelas..   Valeu Emerson.
Responder Citar