I have some select statements that fetch data from multiple tables and usually they are ran many times to update lists on the application for users to see data. Since I'm pretty much new to this whole story about views, I was reading this article how it said views are supposed to replace long queries and are just virtual tables to access data faster and I was wondering how and if should i use views instead of these long queries.
Here are some of my queries
IF @Action = 'SELECTALL'
BEGIN
SELECT hr.IdColaborador, hr.MotivoCriacao, hr.IdReq, Nome, hcb.Email, hr.RefInterna, hi.Descricao AS InfoLog, hs.Descricao AS STATUS, hd.DataAbertura AS DataCriacao FROM hRequisicao AS hr
JOIN hColaborador AS hcb ON hcb.IdColaborador = hr.IdColaborador
JOIN hStatus AS hs ON hs.IdStatus = hr.IdStatus
JOIN hInfoLogistica hi ON hi.IdInfoLogistica = hr.IdInfoLogistica
JOIN hDataLog hd ON hd.IdReq = hr.IdReq
WHERE hr.IdStatus != 6
END
IF @Action = 'SELECTALL_USERID'
BEGIN
SELECT hr.IdColaborador, hr.IdReq, Nome, hcb.Email, hr.RefInterna, hs.Descricao AS STATUS, hl.DataAbertura AS DataCriacao, hi.Descricao AS InfoLog FROM hRequisicao AS hr
JOIN hColaborador AS hcb ON hcb.IdColaborador = hr.IdColaborador
JOIN hStatus AS hs ON hs.IdStatus = hr.IdStatus
JOIN hDataLog AS hl ON hl.IdReq = hr.IdReq
JOIN hInfoLogistica AS hi ON hi.IdInfoLogistica = hr.IdInfoLogistica
WHERE hr.IdColaborador = @IdColaborador AND hr.IdStatus != 6
END
IF @Action = 'SELECT'
BEGIN
SELECT IdReq, hr.MotivoCriacao, hr.IdCodeRequest, hr.IdColaborador, Nome, hcb.Email, Projecto, Desenho, Indice, CadenciaMensal, NumCOMDEV, RefCliente, RefInterna, QTDLancamentoFormas, CapacidadeReal, Peso,
TipoCaixa, QTDPecasCaixa, UnidadeProducao, CelulaProducao, NumKanbansProducao, QTDComp, TipoMetodologia, QTDMetProd, hi.Descricao AS InfoLog FROM hRequisicao AS hr
JOIN hCodeRequest AS hcr ON hr.IdCodeRequest = hcr.IdCodeRequest
JOIN hCaixa AS hc ON hr.IdCaixa = hc.IdCaixa
JOIN hComponentes AS hcp ON hr.IdComp = hcp.IdComp
JOIN hMetodologiaProducao AS hmp ON hr.IdMetProd = hmp.IdMetProd
JOIN hColaborador AS hcb ON hcb.IdColaborador = hr.IdColaborador
JOIN hInfoLogistica AS hi ON hi.IdInfoLogistica = hr.IdInfoLogistica
WHERE IdReq = @IdReq
END
I never used views and I really would like to try to apply them for once to get used to them and see how they work but I'm not confident yet when and how should i use them and if they are like just a place holder to hide the long code