Mudanças entre as edições de "Comandos básicos de SQL"

De MSTECH wiki
Ir para: navegação, pesquisa
Linha 14: Linha 14:
  
 
Exemplo:
 
Exemplo:
INSERT INTO TUR_TurmaDisciplinaTerritorio (tud_idExperiencia,tud_idTerritorio,tte_vigenciaInicio,tte_vigenciaFim
+
 
          ,tte_situacao
+
INSERT INTO TUR_TurmaDisciplinaTerritorio (tud_idExperiencia,tud_idTerritorio,tte_vigenciaInicio,tte_vigenciaFim,tte_situacao,tte_dataCriacao     ,tte_dataAlteracao) VALUES (675828,671601,'2016-08-25','2016-09-10',1,GETDATE(),GETDATE())
          ,tte_dataCriacao
+
          ,tte_dataAlteracao)
+
    VALUES
+
  (675828,671601,'2016-08-25','2016-09-10',1,GETDATE(),GETDATE())
+
 
 
  

Edição das 10h23min de 29 de setembro de 2016

Este guia é um consolidado de comandos básicos que podemos utilizar no dia-a-dia que pode facilitar e agilizar os nossos testes.

Os comandos básicos utilizados no SQL são conhecido como CRUD – Create, Read, Update e Delete. Essas são as operações básicas que uma aplicação realiza em um banco de dados, criação, leitura, atualização e exclusão de dados.

O significado de CRUD é:

Create -> INSERT
Read -> SELECT
Update -> UPDATE
Delete -> DELETE

Insert

insert into [nome_tabela] (campo1, campo2, campo3) values (valor1, valor2, valor3)

Exemplo:

INSERT INTO TUR_TurmaDisciplinaTerritorio (tud_idExperiencia,tud_idTerritorio,tte_vigenciaInicio,tte_vigenciaFim,tte_situacao,tte_dataCriacao ,tte_dataAlteracao) VALUES (675828,671601,'2016-08-25','2016-09-10',1,GETDATE(),GETDATE())


Select

select * from [nome_tabela]  -- consulta simples

select * from CLS_TurmaAula

select * from [nome_tabela] where [condição]  -- consulta com condição

select * from CLS_TurmaAula where tau_data BETWEEN '2016-02-11' AND '2016-02-11'

select * from CLS_TurmaAulaAluno where tud_id in (671036,695177)

select * from tur_turmadisciplina where tud_tipo in (18,19) and tud_nome ='sarau'

select * from CLS_TurmaAula where tau_data BETWEEN '2016-02-11' AND '2016-02-11' and tud_id in (671036,695177) and tau_situacao = 1 order by tau_data desc

select * from [nome_tabela1] [apelido da tabela1] inner join [nome_tabela2] [apeli da tabela2] on [ligação_tabela1]=[ligação_tabela2] where [condição] -- consulta em mais de uma tabela

select * from tur_turmadisciplina tud inner join tur_turmarelturmadisciplina rel on rel.tud_id = tud.tud_id where tud_tipo in (18,19) and tud_codigo = '1B' and tud_nome like '%Educomunicacao%' and tur_id =120532


Update

update [nome_tabela] set [campos alterados] where [condição]

update tur_turmadocente set tdt_vigenciaFim = '2016-12-31' where tud_id = 675828

update CLS_TurmaAula set tau_situacao = 3, tau_dataAlteracao = GETDATE() WHERE tud_id in (670410,670487,670685,670874,671253,671441,675839) AND tau_data BETWEEN '2016-10-03' AND '2016-12-22'

Delete

delete from [nome_tabela] where [condição]

delete from TUR_TurmaDisciplinaTerritorio where tte_id in (624)