Está en la página 1de 10

UNIVERSIDAD ABIERTA PARA ADULTOS

PRESENTADO POR:
Scarly Fco. Cruz Ventura

MATRÍCULA:
16-11084

ASIGNATURA:
Sistema de Base de Datos I

FACILITADOR:
Ing. Joan Tejada Caba

Tarea 3

25 de julio, 2020,
Santiago de los Caballeros, Rep. Dom.
a) Crear una base de datos utilizando la técnica Maestro Detalle, para ello debes
trabajar con con dos entidades principales:
Maestro_Factura  y Detalle_Factura
b) Debes lograr un diseño, el cual permita almacenar datos principales  en la entidad
Maestro_Factura tales como: la fecha de la factura, tipo de factura, código del cliente y
el numero de la factura.
c)  En la entidad Detalle_Factura, se debe almacenar el numero de factura relacionado
con el Maestro_Factura, código del producto, cantidad facturada, y  el precio del
producto.
USE [master]

GO

/****** Object: Database [BASE DE DATOS 1] Script Date: 25/07/2020 22:50:47 ******/

CREATE DATABASE [BASE DE DATOS 1]

CONTAINMENT = NONE

ON PRIMARY

( NAME = N'BASE DE DATOS 1', FILENAME = N'C:\Program Files\Microsoft SQL


Server\MSSQL15.MSSQLSERVER\MSSQL\DATA\BASE DE DATOS 1.mdf' , SIZE = 8192KB ,
MAXSIZE = UNLIMITED, FILEGROWTH = 65536KB )

LOG ON

( NAME = N'BASE DE DATOS 1_log', FILENAME = N'C:\Program Files\Microsoft SQL


Server\MSSQL15.MSSQLSERVER\MSSQL\DATA\BASE DE DATOS 1_log.ldf' , SIZE = 8192KB ,
MAXSIZE = 2048GB , FILEGROWTH = 65536KB )

WITH CATALOG_COLLATION = DATABASE_DEFAULT

GO

ALTER DATABASE [BASE DE DATOS 1] SET COMPATIBILITY_LEVEL = 150

GO

IF (1 = FULLTEXTSERVICEPROPERTY('IsFullTextInstalled'))

begin

EXEC [BASE DE DATOS 1].[dbo].[sp_fulltext_database] @action = 'enable'

end

GO

ALTER DATABASE [BASE DE DATOS 1] SET ANSI_NULL_DEFAULT OFF

GO

ALTER DATABASE [BASE DE DATOS 1] SET ANSI_NULLS OFF

GO

ALTER DATABASE [BASE DE DATOS 1] SET ANSI_PADDING OFF

GO

ALTER DATABASE [BASE DE DATOS 1] SET ANSI_WARNINGS OFF

GO

ALTER DATABASE [BASE DE DATOS 1] SET ARITHABORT OFF

GO
ALTER DATABASE [BASE DE DATOS 1] SET AUTO_CLOSE OFF

GO

ALTER DATABASE [BASE DE DATOS 1] SET AUTO_SHRINK OFF

GO

ALTER DATABASE [BASE DE DATOS 1] SET AUTO_UPDATE_STATISTICS ON

GO

ALTER DATABASE [BASE DE DATOS 1] SET CURSOR_CLOSE_ON_COMMIT OFF

GO

ALTER DATABASE [BASE DE DATOS 1] SET CURSOR_DEFAULT GLOBAL

GO

ALTER DATABASE [BASE DE DATOS 1] SET CONCAT_NULL_YIELDS_NULL OFF

GO

ALTER DATABASE [BASE DE DATOS 1] SET NUMERIC_ROUNDABORT OFF

GO

ALTER DATABASE [BASE DE DATOS 1] SET QUOTED_IDENTIFIER OFF

GO

ALTER DATABASE [BASE DE DATOS 1] SET RECURSIVE_TRIGGERS OFF

GO

ALTER DATABASE [BASE DE DATOS 1] SET DISABLE_BROKER

GO

ALTER DATABASE [BASE DE DATOS 1] SET AUTO_UPDATE_STATISTICS_ASYNC OFF

GO

ALTER DATABASE [BASE DE DATOS 1] SET DATE_CORRELATION_OPTIMIZATION OFF

GO

ALTER DATABASE [BASE DE DATOS 1] SET TRUSTWORTHY OFF

GO

ALTER DATABASE [BASE DE DATOS 1] SET ALLOW_SNAPSHOT_ISOLATION OFF

GO

ALTER DATABASE [BASE DE DATOS 1] SET PARAMETERIZATION SIMPLE

GO

ALTER DATABASE [BASE DE DATOS 1] SET READ_COMMITTED_SNAPSHOT OFF


GO

ALTER DATABASE [BASE DE DATOS 1] SET HONOR_BROKER_PRIORITY OFF

GO

ALTER DATABASE [BASE DE DATOS 1] SET RECOVERY FULL

GO

ALTER DATABASE [BASE DE DATOS 1] SET MULTI_USER

GO

ALTER DATABASE [BASE DE DATOS 1] SET PAGE_VERIFY CHECKSUM

GO

ALTER DATABASE [BASE DE DATOS 1] SET DB_CHAINING OFF

GO

ALTER DATABASE [BASE DE DATOS 1] SET FILESTREAM( NON_TRANSACTED_ACCESS = OFF )

GO

ALTER DATABASE [BASE DE DATOS 1] SET TARGET_RECOVERY_TIME = 60 SECONDS

GO

ALTER DATABASE [BASE DE DATOS 1] SET DELAYED_DURABILITY = DISABLED

GO

EXEC sys.sp_db_vardecimal_storage_format N'BASE DE DATOS 1', N'ON'

GO

ALTER DATABASE [BASE DE DATOS 1] SET QUERY_STORE = OFF

GO

USE [BASE DE DATOS 1]

GO

/****** Object: Table [dbo].[Almacen] Script Date: 25/07/2020 22:50:47 ******/

SET ANSI_NULLS ON

GO

SET QUOTED_IDENTIFIER ON

GO

CREATE TABLE [dbo].[Almacen](

[Codalm] [varchar](4) NOT NULL,

[Desalm] [varchar](max) NULL,


[Estalm] [nchar](1) NULL,

[Colpro] [nchar](2) NULL,

[Filpro] [nchar](2) NULL,

CONSTRAINT [PK_Almacen] PRIMARY KEY CLUSTERED

[Codalm] 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] TEXTIMAGE_ON [PRIMARY]

GO

/****** Object: Table [dbo].[DETALLE_FACTURA] Script Date: 25/07/2020 22:50:47 ******/

SET ANSI_NULLS ON

GO

SET QUOTED_IDENTIFIER ON

GO

CREATE TABLE [dbo].[DETALLE_FACTURA](

[CODPRO] [nchar](10) NULL,

[CANPRO] [nchar](10) NULL,

[PREPRO] [money] NULL,

[NUMFAC] [int] NULL

) ON [PRIMARY]

GO

/****** Object: Table [dbo].[Detalle_Producto] Script Date: 25/07/2020 22:50:47 ******/

SET ANSI_NULLS ON

GO

SET QUOTED_IDENTIFIER ON

GO

CREATE TABLE [dbo].[Detalle_Producto](

[Codpro] [int] NULL,

[Prepro] [int] NULL,

[Despro] [varchar](50) NOT NULL,


[Codalm] [varchar](4) NULL,

CONSTRAINT [PK_Detalle_Producto] PRIMARY KEY CLUSTERED

[Despro] 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].[Existencia] Script Date: 25/07/2020 22:50:47 ******/

SET ANSI_NULLS ON

GO

SET QUOTED_IDENTIFIER ON

GO

CREATE TABLE [dbo].[Existencia](

[Estpro] [nchar](1) NULL,

[Exipro] [int] NOT NULL,

[Codpro] [int] NULL,

CONSTRAINT [PK_Existencia] PRIMARY KEY CLUSTERED

[Exipro] 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].[MAESTRO_FACTURA] Script Date: 25/07/2020 22:50:47


******/

SET ANSI_NULLS ON

GO

SET QUOTED_IDENTIFIER ON

GO

CREATE TABLE [dbo].[MAESTRO_FACTURA](


[NUMFAC] [int] NOT NULL,

[TIPOFAC] [nchar](7) NULL,

[FECFAC] [date] NULL,

[CODCLI] [char](6) NULL,

CONSTRAINT [PK_MAESTRO_FACTURA] PRIMARY KEY CLUSTERED

[NUMFAC] 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].[Productos] Script Date: 25/07/2020 22:50:47 ******/

SET ANSI_NULLS ON

GO

SET QUOTED_IDENTIFIER ON

GO

CREATE TABLE [dbo].[Productos](

[Codpro] [int] NOT NULL,

[Codsup] [int] NULL,

[Cospro] [int] NULL,

CONSTRAINT [PK_Productos] PRIMARY KEY CLUSTERED

[Codpro] 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].[DETALLE_FACTURA] WITH CHECK ADD CONSTRAINT


[FK_DETALLE_FACTURA_MAESTRO_FACTURA] FOREIGN KEY([NUMFAC])

REFERENCES [dbo].[MAESTRO_FACTURA] ([NUMFAC])

GO
ALTER TABLE [dbo].[DETALLE_FACTURA] CHECK CONSTRAINT
[FK_DETALLE_FACTURA_MAESTRO_FACTURA]

GO

ALTER TABLE [dbo].[Detalle_Producto] WITH CHECK ADD CONSTRAINT


[FK_Detalle_Producto_Almacen] FOREIGN KEY([Codalm])

REFERENCES [dbo].[Almacen] ([Codalm])

GO

ALTER TABLE [dbo].[Detalle_Producto] CHECK CONSTRAINT [FK_Detalle_Producto_Almacen]

GO

ALTER TABLE [dbo].[Detalle_Producto] WITH CHECK ADD CONSTRAINT


[FK_Detalle_Producto_Productos] FOREIGN KEY([Codpro])

REFERENCES [dbo].[Productos] ([Codpro])

GO

ALTER TABLE [dbo].[Detalle_Producto] CHECK CONSTRAINT [FK_Detalle_Producto_Productos]

GO

ALTER TABLE [dbo].[Existencia] WITH CHECK ADD CONSTRAINT [FK_Existencia_Productos]


FOREIGN KEY([Codpro])

REFERENCES [dbo].[Productos] ([Codpro])

GO

ALTER TABLE [dbo].[Existencia] CHECK CONSTRAINT [FK_Existencia_Productos]

GO

USE [master]

GO

ALTER DATABASE [BASE DE DATOS 1] SET READ_WRITE

GO

También podría gustarte