How to create an index for two tables at the same time in SQL Server?

3

I'm pretty sure there's no way to do it, come on ...

I have the following scenario: (include only key fields for brevity)

 - Tabela Venda: 
   - id: int;
   - cliente_id: int;
   - cliente_tipo: char(1);
 - Tabela PessoaFisica:
   - id: int;
   - nome: varchar(100);
   - uf: char(2);
 - Tabela PessoaJuridica:
   - id: int;
   - razao_social: varchar(100);
   - uf: char(2);

I did not create the bank and I have to work with it in that way.

My situation is: in certain cases, I have to make queries where I depend on the sale to reach my client and, based on the state where the client is, determine a working rule for it.

The problem is that if my query gets too complex and at many levels of action I realize that the query is slowing down. Then I thought of the indexes.

The problem is that for this, I need to bind an index in the sales table that can relate to both PessoaFisica and PessoaJuridica . Is there any way to do this?

    
asked by anonymous 02.07.2018 / 19:18

1 answer

3

Not possible. It has database that is up has as, but SQL Server can not, nor with functions or columns computed.

One way is to create a mechanism where you always bring the data from the other table to the one that needs the index and use the two columns there. It is the denormalization forced to meet a demand. Care must be taken not to lose consistency.

You need to think if you have any other way to do this. Maybe you can help by view .

    
03.07.2018 / 14:19