Transcript name: 18 Command Editor
English
In this video we provide a general overview of the
DB2 Command Editor.
The DB2 Command Editor is the GUI version of the
DB2 Command Line Processor.
The DB2 Command Editor is deprecated, meaning it will no longer
be enhanced and may not be available in future versions of DB2.
The Command Editor can be started using this button here,
So if you click here, you can start the Command Editor.
You can also start it from Start > Programs > IBM db2 > db2copy 1 >
Command Line Tools > and then you have the Command Editor,
so that will be the long way to do it. The second way is within the
Control Center, you can click on this button.
Another way to do it is to click on Start > Run and type db2ce.
All of these commands, db2cc, db2ce, and more that I will show you
later could be used in Linux as well to start the different
graphical tools, which are exactly the same as the
ones I'm showing you here on this Windows demo.
So let me start another window for the Command Editor,
“c” is for command, “e” is for editor, so it's easy to remember.
Then if I click ok, I will be starting another window,
so now I have two Command Editor windows, Command Editor 1 and 2.
Nesse vídeo nós damos uma visaõ geral sobre o
Editor de Comandos do DB2 (DB2 Command Editor).
O Editor de Comandos do DB2 é a versão gráfica do
Processador de Linha de Comando do DB2 (DB2 Command Line Processor).
O Editor de Comando do DB2 está
descontinuado, ou seja, ele não sofrerá mais
melhorias e pode não estar disponível em futuras versões do DB2.
O Editor de Comando pode ser iniciado utilizando esse botão aqui;
então, se você clicar aqui, você pode iniciar o Editor de Comandos.
Você pode iniciá-lo também a partir do Iniciar -> Programas -> IBM DB2 -> db2copy1 ->
Ferramenta de Linha de Comandos -> e então você estará no Editor de Comandos,
mas esse é o caminho maus longo para fazer isso. A outra maneira é a partir do
Control Center, você pode clicar nesse botão.
Outra maneira de fazer isso é clicar em Iniciar -> Executar e digitar db2ce. Todos esses comandos, db2cc, db2ce e mais que eu mostrarei depois
podem ser usados no Linux também para iniciar as
diferentes ferramentas gráficas, que são exatamente as mesmas
mostradas aqui na demonstração do Windows.
Vamos então iniciar outra janela para o Editor de Comandos,
'c' é para comando e 'e' é para editor, então é fácil de lembrar.
Então, se eu clicar OK, iniciarei outra janela,
então agora tenho 2 janelas do Editor de Comandos, 1 e 2.
Ok, let me just close one (that was just for demonstration
purposes). Now let me just show you what you can do with the
Command Editor. From here you can click on Add and let's say again,
you are going to use the SAMPLE database, and click OK,
and that's how you will be connecting to the SAMPLE database.
Another way to disconnect, from here you can choose the blank
space, and that will be disconnecting, which is invoking the
Connect Reset command. From here you can also do a connect,
you can say, connect to sample, and then click on this button to
execute. Now I'm connected, so I can connect by using the Add
button, or just by executing the command. And also from
here I just do connect reset, if I want to reset the connection,
so the reset is finished. Or, I can do many other commands.
So let me connect again to sample, and this time I'm going to put
a semicolon here; I'll explain what that means in a minute,
and then I'm going to do select * from employee; (semicolon),
select * from department; (semicolon). Then I'm going to right-click on this area and I'm going to choose
Clear results; you don't need to clear the results, but I want you
to see that I'm getting new results here. So why do we need this semicolon for each statement?
Well the semicolon indicates that that's the end of the statement.
For the first case, when I was doing a connect to sample, and that
Ok, deixe-me agora fechar uma (que era apenas para demonstração)
Agora deixe-me mostrar-lhe o que eu posso fazer com o
Editor de Comandos. Daqui você pode clicar em 'Adicionar' (Add) e digamos
você vai usar a base de dados SAMPLE, e clicar OK,
e é assim que se conecta à base de dados SAMPLE.
Uma outra forma de se desconectar, daqui você pode esclher espaço em
branco, e isso irá desconectar, que é o mesmo que
chamar o comando Connect Reset. Daqui, você também pode fazer uma conexão, digamos, conectar ao SAMPLE, e então clicar nesse botão para
executar. Agora, estou conectado, então posso conectar usando o botão Adicionar (Add),
ou apenas executando o comando. E também daqui
eu apenas executo Connect Reset, se eu quiser fechar a conexão,
então a conexão está terminada. Ou, eu posso fazer vários outros comandos. Vamos conectar outra vez ao SAMPLE, e dessa vez vou colocar
um ponto-e-vírgula aqui; Vou explicar o que isso significa em um instante, e então vou fazer um 'select * from employee;' (ponto-e-vírgula),
select * from department; (ponto-e-vírgula).
Vou clicar com o botão direito nessa área e escolher
'Limpar resultados' (Clear results); você não precisa limpar os resultados, mas quero que
você veja que estou obtendo novos resultados aqui.
Então, por que precisamos do ponto-e-vírgula para cada comando?
Bem, o ponto-e-vírgula indica que é o fim da linha de comando.
Para o primeiro caso, quando eu estava fazendo uma conexão ao SAMPLE, e que
was the only sentence, or the only query, then I didn't need to put
a semicolon because that was the only one, but in the case where I
have several statements, in the screen, then I need to put a
semicolon because DB2 will execute each statement,
one after the other, like a script. So if I now execute this, and by the way, here at the bottom
you will see what the statement terminator character is,
in this case it's the semicolon; the semicolon is the one
used by default. You can change it from here, let's change it now,
if I change it to the @ symbol, I will have to change it here,
here, and here, so that DB2 knows exactly how to, or what is the
statement terminator for each statement. Now if I click here to execute, DB2 will execute the three
statements one after the other: this one first, then this one,
and then the third statement. So if I look at the results,
I'm going to go up to the top, so I scroll up to the top,
and then you can see that it executed the connect to sample
and this is the output; then it executed select * from employee
and all of this is the output; and then it executed select * from
department and this is the output. So it executed the three of those statements, one after the other. Let me clear the results here;
let's put back the original semicolon as the terminator.
And now what I'm going to do is, if I just want to execute one
era a única sentença, ou a única consulta, então eu não precisava colocar
um ponto-e-vírgula porque era o único, mas no caso onde eu
tenho vários comandos na tela, então eu preciso colocar um
ponto-e-vírgula porque o DB2 executará cada comando,
um após o outro, como um script.
Se agora eu executar isso, e à propósito, aqui em baixo
você verá qual que o caracter terminador de comando é,
nesse caso, o vírgula; o ponto-e-vírgula é
usado por padrão. Você pode alterá-lo aqui, vamos fazê-lo agora,
se eu alterar para o símbolo @, terei que alterá-lo aqui,
aqui e aqui, para que o DB2 possa saber exatamente como, ou qual é o
terminador de comando para cada um.
Agora se eu clicar aqui para executar, DB2 irá executar 3
comandos, um após o outro: esse primeiro, depois esse,
e então o terceiro. Se eu olhar nos resultados,
vou até o topo da tela, rolo até o topo da tela,
e então você pode ver que eu executei a conexão ao SAMPLE
e essa é a saída; então executei 'select * from employee'
e tudo isso é a sáida; depois foi executado 'select * from
department' e aqui está a saída.
Então, ele executou aqueles 3 comandos, um após o outro.
Deixe-me limpar os resultados;
vamos colocar de volta o ponto-e-vírgula original como terminador de comando. E agora o que vou fazer é, se eu quiser executar apenas
statement, and not the three of them, let's say I just want to
execute the second one, I can highlight it the way I did it here,
and I can execute, and it will only execute one statement.
Now we’ve got the output in a different tab and that's the default
behavior if you get the result of just one query, to just
display it on a different tab called the Query Results tab.
Now if you don't like this, and I particularly don't like it
and when we talk about XML, you will see that it's not good to
present the results like this.
So normally what I do is I go to Tools > Tools Settings
and I choose Command Editor (let me maximize this window)
and I remove this checkbox from here, right; so let me close this, let me close this, and let's just close this
to make sure the changes take effect.
And let's start the Command Editor again, so if I type Command
Editor again, then it should start the Command Editor and we will
make sure if I now quickly type connect to sample,
select * from employee, select * from department.
Now, let me first of all connect from sample from here because what
I wanted to do.. let me just clear the results,
is to highlight this statement,
this time if I click on the run button, you can see now the output is appearing on this same window.
The reason that it's appearing on this window and not on the
Query Results tab is because of the change
um comando, e não os três, digamos apenas o
segundo, eu posso destacá-lo como fiz aqui,
e posso executar, e apenas esse comando será executado.
Agora nós temos a saída em uma janela diferente, e esse é o comportamento padrão se você quiser o resultado de apenas uma consulta, para
exibí-lo em uma janela diferente chamada 'Query Results' (Resultado da Consulta). Se você não gostar disso, e eu
particularmente não gosto,
e quando falarmos sobre XML, você verá que isso não é bom
para apresentar os resultados.
Então, normalmente o que eu faço é ir em TOOLS -> TOOLS SETTINGS
escolho Command Editor (vamos maximizar essa janela)
e removo essa caixa de checagem daqui, certo;
deixe-me fechar este, fechar este, e vamos apenas fechar este
para ter certeza que as alterações terão efeito.
Agora vamos reiniciar o Editor de Comandos, então eu digito Command
Editor outra vez, e isso deveria iniciar o Editor de Comando e nos certificaremos se eu rapidamente me conectar ao SAMPLE,
'select * from employee', 'select * from department'.
Agora, deixe-me antes de tudo conectar ao SAMPLE daqui, porque o que
eu quero é fazer... deixe-me limpar os resultados,
é destacar esse comando, agora se eu clicar no botão 'RUN' (executar),
você verá a saída aparecendo na mesma janela.
A razão pela qual está aparecendo nessa janela e não na
that we just made in
Tools > Tools Settings, the one I showed you before,
Command Editor, and then this one; we got rid of this one,
so that's why we are getting the results on this line.
Again, this is probably the best way to display the results,
especially for XML.
Anyway, as you can see, when I executed just the second line,
when I highlighted it, if I go up, it shows me that it only
executed one statement, great. I'm going to clear the results here. Now what else can I do here? Well, I can also click on this button
here, which is to show me some history on my current session.
On this session, I just executed only this select * from employee,
but I can select it and choose paste and in this case it pasted it
where my cursor was, but there is select * from employee,
so it's just a history to save some time; so that you can copy
and paste. Another thing you can do from here, let me delete this,
is that you could save this into a file. So you could specify where you want to save this and later on
you could — so, let's say I'm going to put it in this directory
called erase and I'm going to call it raulscript,
I can say .txt and say OK.
So basically, I just saved this into a file and I just created a
script, right; if I want to run that script later on, I can open
from here and I can look for that script in the erase database and
alteração feita em
TOOLS -> TOOLS SETTINGS, a que eu mostrei antes,
Editor de Comandos, e então essa aqui; nós nos livramos dessa aqui,
por isso nós obtivémos os resultados nessa linha.
Outra vez, este é provavelmente a melhor maneira para mostrar os resultados, especialmente para XML.
De qualquer maneira, como você pode ver, quando eu executo apenas a segunda linha, quando eu a destaco, se eu for para cima, ele me mostra que executou
apenas um comando. Bom !
Vou limpar os resultados aqui.
Agora, o que mais posso fazer aqui? Bem, eu tmbém posso clicar sobre esse botão aqui, que me mostra alguns históricos da minha sessão atual.
Nessa sessão, eu apenas executei 'select * from employee',
mas eu posso selecioná-lo e escolher colar e, nesse caso, ele colou
onde meu cursor estava, mas há um 'select * from employee',
então é apenas uma forma para economizar tempo; então você pode copiar
e colar. Outra coisa que se pode fazer daqui, deixe-me deletar isso,
é que você pode salvar em um arquivo. Então, você poderia definir onde você quer salvar e mais tarde
você poderia recuperar. Então, digamos que vou gravar nesse diretório
chamado ERASE e vou chamar o arquivo de RAULSCRIPT,
posso especificar .txt e dar OK.
Basicamente, eu apenas salvei num arquivo e criei um
script, certo? Se eu quiser executar aquele script posteriormente, posso abrir aqui e procurar por aquele script na base de dados ERASE e
I'm going to look for raulscript, which is there, so I click OK,
and say Yes. And then you can see that my file is open, and my
script is open and I can execute it by executing, by clicking on
those three lines and you get all the results back again, great.
Now what else can we do from the Command Editor?
From the Command Editor I can also choose let's say this
particular statement, and I can click on this third button and
what that will do is create a graph. This is called Visual Explain,
and Visual Explain shows you how DB2 is accessing your information,
your data, so in this case it's first accessing the department
table, and it's doing a table scan that is costing 7.61 timerons,
and that's the final return.
Timerons are a special unit in DB2, and basically they are used
to determine the cost of this query—but timerons depend on
where you're running this query, because the calculation of a
timeron is based on the CPU speed, on memory, etc. etc.
So you may be running this same query on a different computer and
you may get a different value for the timerons.
So timerons are good if you'll be running the same query on the
same machine and you see a reduction on the cost of the timerons,
so then you can tell that you are improving the
cost of this query and the performance of this query.
You can also double-click on these buttons here,
vou procurar por RAULSCRIPT, que está aqui, clico OK,
e digo YES. Você pode ver que meu arquivo está aberto, meu
script está aberto e posso executá-lo clicando sobre
essas 3 linhas, e obteremos todos os resultados novamente.
Agora, o que mais podemos fazer a partir do Editor de Comando?
Também posso escolher, digamos esse
comando em particular, e posso clicar nesse terceiro botão e
o que isso faz é criar um gráfico. Isso é chamado Visual Explain,
o Visual Explain mostra como DB2 está acessando suas informações,
seus dados, então nesse caso ele está primeiramente acessando a tabela
departamento, e está fazendo uma varredura de tabela que custa 7.61 timerons,
e esse é o resultado final.
Timeron é uma unidade especial do DB2, e basicamente é usado para
determinar o custo da consulta, mas o timeron depende de
onde você executa a consulta, porque o cálculo de um
timeron é baseado na velocidade da CPU, memória, etc., etc.
Portanto, você poderia executar a mesma consulta em um computador diferente e obter um valor diferente para timeron.
Então, timerons são bons se você for executar a mesma consulta na
mesma máquina e você vir uma redução de custos de timerons,
nesse caso você pode dizer que está melhorando o
custo e a performance dessa consulta.
Você também pode dar um duplo-clique nesses botões aqui,
and you get more information, and that may be useful to you when
you're doing performance analysis.
Now if I do, for example, I start from that where that number is
equal to E01 and I execute this third button, you will see that in
this case you get a different access plan, where rather than doing
a table scan as in the case before, I'm doing an index scan.
An index scan, what it will do is… I'm looking at this table,
and using an index, which is PKdept, which happens to be a primary
key and then doing an index scan and from there, this cost is 0.03.
Then I'm going to do a fetch, which is: I look at the index,
I scan the index, then I find what I want, and then from the index
I will point, or I will have to go to the table data, so I'll fetch
from the table data, and that will cost the cumulative of this,
which is 7.6, and then the final cost it will be 7.6.
Anyway, that's just to give you a quick overview of what could do
with the Command Editor.
This concludes this presentation. Thank you for watching.
To learn more, visit db2university.com
e obter mais informações, que podem ser úteis para você quando
estiver fazendo análise de performance. Agora se eu fizer, por exemplo, iniciar dali onde o número é
igual à E01 e executar esse terceiro botão, você verá que
nesse caso você obtem um plano de acesso diferente, que ao invés de fazer
uma varredura de tabela como antes, está fazendo uma varredura de índice.
Nma varredura de índice, o que ele faz é... Estou olhando nessa tabela,
e usando um índice, que é Pkdept, que é uma chave
primária e então, fazendo uma varredura de índice daqui, o custo é 0,03.
Então estou fazendo uma busca, que é: eu procuro no índice,
varro o índice, encontro o que eu quero, e então, do índice
eu aponto, ou tenho que ir aos dados da tabela, então eu busco
dos dados da tabela, e o custo será acumulativo,
que é 7.6, então o custo final será 7.6.
De qualquer maneira, isso é apenas para da um panorama do que se pode fazer
com o Editor de Comando. Isso conlcui a apresentação. Obrigado por assistir.
Para aprender mais, visite o site db2university.com