Insert Select Sql Server

0

Connection and Historico_ligacao

I have a script that copies all data from table Ligacao to Historico_ligacao .

When comparing the data between the tebalas, the historico_ligacao table is ordered differently than Ligacao , I do not know if it influences anything, but I would like the ordering of both to be equal.

Below is the insert code:

SET IDENTITY_INSERT HISTORICO_LIGACAO ON
INSERT HISTORICO_LIGACAO (CDLIGACAO,CDLOTE,CDATRIBUTOLOTE,CDCAMPANHA,CDROTA,CDCONTATO,CDTELEFONE,CDESTADOLIGACAO,DURACAO,DTINICIO,DTFINAL,NUMERO_DISCADO,TECLAS_VALIDAS,TECLAS_TODAS, timezone)
output inserted.CDLIGACAO into #temp (num)
SELECT * FROM LIGACAO WHERE CDLOTE <= @CDLOTE order by cdligacao;
SET IDENTITY_INSERT HISTORICO_LIGACAO OFF

    
asked by anonymous 04.12.2017 / 19:52

2 answers

1

Create clustered index in column CDLIGACAO

If the records are unique it also places it as the primary key.

CREATE CLUSTERED INDEX idx_name ON HISTORICO_LIGACAO (CDLIGACAO);  
    
04.12.2017 / 23:23
1

@Junior Torres The order of presentation does not influence anything. But if you want to display them in an organized way, you can use the order by statement. In your case it would look like this:

SELECT * FROM LIGACAO ORDER BY CDLIGACAO;
SELECT * FROM HISTORICO_LIGACAO ORDER BY CDLIGACAO;
    
05.12.2017 / 00:02