This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Base de Datos
Ramiro Cusilayme Aguilar Página 1
Inner Join
CREATE DATABASE FARMACIA
USE FARMACIA
create table producto(
cod_pro int identity (1,1)primary key not null,
fecha_ven_pro smalldatetime not null,
descrip_pro nvarchar(50) not null,
precio_pro nvarchar(50) not null
)
create table personal(
cod_per int identity (1,1)primary key not null,
nombre_per nvarchar (50)not null,
apellido_per nvarchar (50)not null ,
direccion_per nvarchar (50) not null
)
create table cliente (
cod_cli int identity (1,1)primary key ,
nombre_cli nvarchar (50)not null,
apellido_cli nvarchar (50)not null ,
direccion_cli nvarchar (50) not null
)
Con alias SELECT * FROM PRODUCTO PR INNER JOIN PERSONAL PE
ON PR.cod_pro = PE.cod_per
Base de Datos
Ramiro Cusilayme Aguilar Página 2
Sin alias
SELECT * FROM producto INNER JOIN personal
ON producto.cod_pro = personal.cod_per
RELACIONAMIENTO INTERNO DE ENTIDADES
1ºPrimera forma SELECT A.descrip_pro,B.nombre_per FROM producto A, personal B
WHERE A.cod_pro = B.cod_per
Base de Datos
Ramiro Cusilayme Aguilar Página 3
2º Segunda Forma SELECT descrip_pro, nombre_per FROM producto INNER JOIN personal ON producto.cod_pro = personal.cod_per
3ºTercera Forma
Con alias
SELECT a.descrip_pro, b.nombre_per,c.nombre_cli FROM producto a INNER
JOIN personal b
ON a.cod_pro= b.cod_per INNER JOIN cliente c ON c.cod_cli = b.cod_per