#+title: Actividad2

#+begin_src sql
    USE [master]
GO
/****** Object:  Database [Vuelos]    Script Date: 7/4/2025 23:02:58 ******/
CREATE DATABASE [Vuelos]
GO
USE [Vuelos]
GO
/****** Object:  Table [dbo].[Aviones]    Script Date: 7/4/2025 23:02:58 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Aviones](
	[id_avion] [int] NOT NULL,
	[id_prop] [int] NULL,
	[cant_p] [int] NULL,
	[anio] [int] NULL,
	[matricula] [nvarchar](60) NULL,
PRIMARY KEY CLUSTERED
(
	[id_avion] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[Escalas]    Script Date: 7/4/2025 23:02:58 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Escalas](
	[id_escala] [int] NOT NULL,
	[id_vuelo] [int] NULL,
	[id_avion] [int] NULL,
	[ori] [nvarchar](60) NULL,
	[dest] [nvarchar](60) NULL,
PRIMARY KEY CLUSTERED
(
	[id_escala] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[Localidades]    Script Date: 7/4/2025 23:02:58 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Localidades](
	[cp] [int] NOT NULL,
	[localidad] [nvarchar](60) NULL,
PRIMARY KEY CLUSTERED
(
	[cp] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[Pasajeros]    Script Date: 7/4/2025 23:02:58 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Pasajeros](
	[dni] [nvarchar](12) NOT NULL,
	[apellido] [nvarchar](10) NULL,
	[nombre] [nvarchar](10) NULL,
	[telefono] [nvarchar](20) NULL,
	[mail] [nvarchar](60) NULL,
	[cp] [int] NULL,
PRIMARY KEY CLUSTERED
(
	[dni] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[Propietarios]    Script Date: 7/4/2025 23:02:58 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Propietarios](
	[id_prop] [int] NOT NULL,
	[cuit] [nvarchar](13) NULL,
	[domicilio] [nvarchar](60) NULL,
	[nombre] [nvarchar](12) NULL,
	[apellido] [nvarchar](12) NULL,
	[cp] [int] NULL,
PRIMARY KEY CLUSTERED
(
	[id_prop] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[Vuelos]    Script Date: 7/4/2025 23:02:58 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Vuelos](
	[id_vuelo] [int] NOT NULL,
	[ori] [nvarchar](12) NULL,
	[dest] [nvarchar](12) NULL,
	[km] [int] NULL,
	[fecha] [date] NULL,
	[horas] [nvarchar](6) NULL,
	[horaa] [nvarchar](6) NULL,
	[id_avion] [int] NULL,
PRIMARY KEY CLUSTERED
(
	[id_vuelo] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[Vuelos_pasajeros]    Script Date: 7/4/2025 23:02:58 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Vuelos_pasajeros](
	[id_vuelo] [int] NOT NULL,
	[dni] [nvarchar](12) NOT NULL,
PRIMARY KEY CLUSTERED
(
	[id_vuelo] ASC,
	[dni] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[Aviones]  WITH CHECK ADD FOREIGN KEY([id_prop])
REFERENCES [dbo].[Propietarios] ([id_prop])
GO
ALTER TABLE [dbo].[Escalas]  WITH CHECK ADD FOREIGN KEY([id_avion])
REFERENCES [dbo].[Aviones] ([id_avion])
GO
ALTER TABLE [dbo].[Escalas]  WITH CHECK ADD FOREIGN KEY([id_vuelo])
REFERENCES [dbo].[Vuelos] ([id_vuelo])
GO
ALTER TABLE [dbo].[Pasajeros]  WITH CHECK ADD FOREIGN KEY([cp])
REFERENCES [dbo].[Localidades] ([cp])
GO
ALTER TABLE [dbo].[Propietarios]  WITH CHECK ADD FOREIGN KEY([cp])
REFERENCES [dbo].[Localidades] ([cp])
GO
ALTER TABLE [dbo].[Vuelos]  WITH CHECK ADD FOREIGN KEY([id_avion])
REFERENCES [dbo].[Aviones] ([id_avion])
GO
ALTER TABLE [dbo].[Vuelos_pasajeros]  WITH CHECK ADD FOREIGN KEY([id_vuelo])
REFERENCES [dbo].[Vuelos] ([id_vuelo])
GO
ALTER TABLE [dbo].[Vuelos_pasajeros]  WITH CHECK ADD FOREIGN KEY([dni])
REFERENCES [dbo].[Pasajeros] ([dni])
GO
USE [master]
GO
ALTER DATABASE [Vuelos] SET  READ_WRITE
GO




#+end_src
