Insert Select Sql Server

Asked

Viewed 259 times

0

Connection and Historico_ligacao

I have a script which copies all data from the table Ligacao for Historico_ligacao.

When I compare the data between the theban, the table historico_ligacao is arranged in a different way from Ligacao, I don’t know if this influences anything, but I would like the ordination of both to be equal.

Below is the code of Insert:

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

printscreen do resultset

2 answers

1


Create clustered index in column CDLIGACAO

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

CREATE CLUSTERED INDEX idx_name ON HISTORICO_LIGACAO (CDLIGACAO);  

1

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

SELECT * FROM LIGACAO ORDER BY CDLIGACAO;
SELECT * FROM HISTORICO_LIGACAO ORDER BY CDLIGACAO;

Browser other questions tagged

You are not signed in. Login or sign up in order to post.