Novedades SQL Server 2014: Escalabilidad | Lanzamiento SQL Server 2014
SQL
-
Upload
johnatan-herrera-retamal -
Category
Documents
-
view
222 -
download
3
description
Transcript of SQL
![Page 1: SQL](https://reader037.fdocuments.ec/reader037/viewer/2022103021/563dba42550346aa9aa412d7/html5/thumbnails/1.jpg)
![Page 2: SQL](https://reader037.fdocuments.ec/reader037/viewer/2022103021/563dba42550346aa9aa412d7/html5/thumbnails/2.jpg)
Cardinalidad
![Page 3: SQL](https://reader037.fdocuments.ec/reader037/viewer/2022103021/563dba42550346aa9aa412d7/html5/thumbnails/3.jpg)
Cardinalidad
� Relación de cardinalidad 1 a N � Debemos diseñar entonces una clave
foránea en la tabla debil que corresponde a la llave principal de la tabla fuerte. ○ Ej:CURSOS para alojar valores que son clave
primaria de la tabla PROFESORES. En este caso diseñaremos un campo que llamaremos ID_PROFE, aunque se podría llamar de cualquier otro modo, que contendrá el identificador de profesor que imparte el curso que representa cada registro
![Page 4: SQL](https://reader037.fdocuments.ec/reader037/viewer/2022103021/563dba42550346aa9aa412d7/html5/thumbnails/4.jpg)
Cardinalidad
![Page 5: SQL](https://reader037.fdocuments.ec/reader037/viewer/2022103021/563dba42550346aa9aa412d7/html5/thumbnails/5.jpg)
Totalizadores
select sum(SALARIO) from EMPLEADOS select count(*) from EMPLEADOS select sum(SALARIO) / count(*) from EMPLEADOS
![Page 6: SQL](https://reader037.fdocuments.ec/reader037/viewer/2022103021/563dba42550346aa9aa412d7/html5/thumbnails/6.jpg)
Totalizadores
select avg(SALARIO) as MEDIA_SALARIOS from EMPLEADOS Select max(SALARIO) from EMPLEADOS Select max(SALARIO) from EMPLEADOS
![Page 7: SQL](https://reader037.fdocuments.ec/reader037/viewer/2022103021/563dba42550346aa9aa412d7/html5/thumbnails/7.jpg)
Agrupadores select SEXO , count(*) as EMPLEADOS from EMPLEADOS group by SEXO
SEXO EMPLEADOS H 2 M 2
select SEXO , count(*) as EMPLEADOS from EMPLEADOS
SEXO EMPLEADOS H 4
![Page 8: SQL](https://reader037.fdocuments.ec/reader037/viewer/2022103021/563dba42550346aa9aa412d7/html5/thumbnails/8.jpg)
Agrupadores Having select SEXO , count(*) as EMPLEADOS from EMPLEADOS group by SEXO Having Count(*)=1
SEXO EMPLEADOS H 2 M 2
select SEXO , count(*) as EMPLEADOS from EMPLEADOS
SEXO EMPLEADOS H 4
![Page 9: SQL](https://reader037.fdocuments.ec/reader037/viewer/2022103021/563dba42550346aa9aa412d7/html5/thumbnails/9.jpg)
Ordenar select NOMBRE,APELLIDOS,SALARIO from EMPLEADOS order by SALARIO select NOMBRE,APELLIDOS,SALARIO from EMPLEADOS order by SALARIO desc select * from EMPLEADOS where ESPECIE = 'P' order by SEXO desc, NOMBRE asc
![Page 10: SQL](https://reader037.fdocuments.ec/reader037/viewer/2022103021/563dba42550346aa9aa412d7/html5/thumbnails/10.jpg)
alias select NOMBRE as NAME, APELLIDOS as SURNAMES, SALARIO as SALARY from EMPLEADOS order by SURNAMES
![Page 11: SQL](https://reader037.fdocuments.ec/reader037/viewer/2022103021/563dba42550346aa9aa412d7/html5/thumbnails/11.jpg)
Like select * from EMPLEADOS where APELLIDOS like 'R%’ select * from EMPLEADOS where APELLIDOS like ’%S' select * from EMPLEADOS where APELLIDOS like ’%io%'
![Page 12: SQL](https://reader037.fdocuments.ec/reader037/viewer/2022103021/563dba42550346aa9aa412d7/html5/thumbnails/12.jpg)
between
select * from VEHICULOS where not (ULTI_ITV between '20080101' and '20081231') or ULTI_ITV is null
![Page 13: SQL](https://reader037.fdocuments.ec/reader037/viewer/2022103021/563dba42550346aa9aa412d7/html5/thumbnails/13.jpg)
Inner Join
select * from CURSOS C inner join PROFESORES P on C.ID_PROFE = P.ID_PROFE Select * from CURSOS, PROFESOR where
C.ID_PROFE = P.ID_PROFE
![Page 14: SQL](https://reader037.fdocuments.ec/reader037/viewer/2022103021/563dba42550346aa9aa412d7/html5/thumbnails/14.jpg)
Left outer join
select * from CURSOS C left outer join PROFESORES P on C.ID_PROFE = P.ID_PROFE
![Page 15: SQL](https://reader037.fdocuments.ec/reader037/viewer/2022103021/563dba42550346aa9aa412d7/html5/thumbnails/15.jpg)
Otras Funciones SQL
� Concatenar select concat('Esto ','es ','un ','ejemplo ', 'de ','concatenación ', 'de ', 'cadenas ', 'de ','texto.') as EJEMPLO_CONCAT
![Page 16: SQL](https://reader037.fdocuments.ec/reader037/viewer/2022103021/563dba42550346aa9aa412d7/html5/thumbnails/16.jpg)
Otras funciones SQL
� Localtime y Current_date
select localtime , current_date
![Page 17: SQL](https://reader037.fdocuments.ec/reader037/viewer/2022103021/563dba42550346aa9aa412d7/html5/thumbnails/17.jpg)
Otras funciones SQL
� Formato Fecha
select date_format(localtime,'%m-%Y') select ID_EMPLEADO, NOMBRE, APELLIDOS, date_format(F_NACIMIENTO,'%d-%m-%Y') F_NACIMIENTO FROM EMPLEADOS
![Page 18: SQL](https://reader037.fdocuments.ec/reader037/viewer/2022103021/563dba42550346aa9aa412d7/html5/thumbnails/18.jpg)
Otras funciones SQL
select date_add(current_date, INTERVAL 30 DAY) FECHA_ACTUAL_MAS_TREINTA_DIAS, date_add(current_date, INTERVAL 6 MONTH) FECHA_ACTUAL_MAS_SEIS_MESES
FECHA_ACTUAL_MAS_TREINTA_DIAS FECHA_ACTUAL_MAS_SEIS_MESES
2015-05-08 2015-10-08
Funciones de Fechas: Date_add o Date_Sub: Agregar o restar fechas
![Page 19: SQL](https://reader037.fdocuments.ec/reader037/viewer/2022103021/563dba42550346aa9aa412d7/html5/thumbnails/19.jpg)
Otras funciones SQL
select * from vehiculos where datediff(PROX_ITV,'2009-11-15') < 31
ID_VEHICULO MARCA MODELO PROX_ITV ULTI_ITV 2 Kia Sorento 2009-12-01 2008-12-01
Funciones de Fechas: datediff: Diferencias de Fechas
![Page 20: SQL](https://reader037.fdocuments.ec/reader037/viewer/2022103021/563dba42550346aa9aa412d7/html5/thumbnails/20.jpg)
Otras Funciones SQL
� Extraer cadena de un texto select substr('ABCDEFGHIJ',1,4) LOS_CUATRO_PRIMEROS_CARACTERES
![Page 21: SQL](https://reader037.fdocuments.ec/reader037/viewer/2022103021/563dba42550346aa9aa412d7/html5/thumbnails/21.jpg)
If select NOMBRE , if(RUBIA='S',’Si,'No') RUBIA from PERSONAS NOMBRE RUBIA Manuel Si Maria No Carmen Si José Si Pedro No
![Page 22: SQL](https://reader037.fdocuments.ec/reader037/viewer/2022103021/563dba42550346aa9aa412d7/html5/thumbnails/22.jpg)
Otras funciones SQL
� Redondear y Truncar
select round(7.64739836953 , 2) , truncate(7.64739836953 , 0) round(7.64739836953 , 2) truncate(7.64739836953 , 0)
7.65 7