0% found this document useful (0 votes)
64 views

Practica Final SQL Notas

This document contains the SQL scripts to create a database called Refricentro_Bernardo1 on a SQL Server instance, along with scripts to create tables for sectors, municipalities, provinces, regions, clients, and products within the database. Tables are created with primary keys and columns for descriptions and foreign key relationships between the geographic hierarchy tables. Settings are also configured on the database for recovery, compatibility, and other options.

Uploaded by

Goruto
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
64 views

Practica Final SQL Notas

This document contains the SQL scripts to create a database called Refricentro_Bernardo1 on a SQL Server instance, along with scripts to create tables for sectors, municipalities, provinces, regions, clients, and products within the database. Tables are created with primary keys and columns for descriptions and foreign key relationships between the geographic hierarchy tables. Settings are also configured on the database for recovery, compatibility, and other options.

Uploaded by

Goruto
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 7

{"metadata":{"kernel_spec":

{"name":"SQL","language":"sql","display_name":"SQL"},"language_info":
{"name":"sql","version":""}},"nbformat":4,"nbformat_minor":2,"cells":
[{"cell_type":"markdown","source":["# [Refricentro_Bernardo1]"],"metadata":
{"urn":"Server[@Name='DESKTOP-PEKDQ0L\\SQLEXPRESS']/
Database[@Name='Refricentro_Bernardo1']","object_type":"Database"}},{"outputs":
[],"execution_count":0,"cell_type":"code","source":["USE [master]\r\n","GO\r\
n"],"metadata":{"urn":"Server[@Name='DESKTOP-PEKDQ0L\\SQLEXPRESS']/
Database[@Name='Refricentro_Bernardo1']","object_type":"Database"}},{"outputs":
[],"execution_count":0,"cell_type":"code","source":["/****** Object: Database
[Refricentro_Bernardo1] Script Date: 25/08/2022 19:46:24 ******/\r\nCREATE
DATABASE [Refricentro_Bernardo1]\r\n CONTAINMENT = NONE\r\n ON PRIMARY \r\n( NAME
= N'Refricentro_Bernardo1', FILENAME = N'C:\\Program Files\\Microsoft SQL Server\\
MSSQL15.SQLEXPRESS\\MSSQL\\DATA\\Refricentro_Bernardo1.mdf' , SIZE = 8192KB ,
MAXSIZE = UNLIMITED, FILEGROWTH = 65536KB )\r\n LOG ON \r\n( NAME =
N'Refricentro_Bernardo1_log', FILENAME = N'C:\\Program Files\\Microsoft SQL
Server\\MSSQL15.SQLEXPRESS\\MSSQL\\DATA\\Refricentro_Bernardo1_log.ldf' , SIZE =
8192KB , MAXSIZE = 2048GB , FILEGROWTH = 65536KB )\r\n WITH CATALOG_COLLATION =
DATABASE_DEFAULT\r\n","GO\r\n","ALTER DATABASE [Refricentro_Bernardo1] SET
COMPATIBILITY_LEVEL = 150\r\n","GO\r\n","IF (1 =
FULLTEXTSERVICEPROPERTY('IsFullTextInstalled'))\r\nbegin\r\nEXEC
[Refricentro_Bernardo1].[dbo].[sp_fulltext_database] @action = 'enable'\r\nend\r\
n","GO\r\n","ALTER DATABASE [Refricentro_Bernardo1] SET ANSI_NULL_DEFAULT OFF \r\
n","GO\r\n","ALTER DATABASE [Refricentro_Bernardo1] SET ANSI_NULLS OFF \r\n","GO\r\
n","ALTER DATABASE [Refricentro_Bernardo1] SET ANSI_PADDING OFF \r\n","GO\r\
n","ALTER DATABASE [Refricentro_Bernardo1] SET ANSI_WARNINGS OFF \r\n","GO\r\
n","ALTER DATABASE [Refricentro_Bernardo1] SET ARITHABORT OFF \r\n","GO\r\n","ALTER
DATABASE [Refricentro_Bernardo1] SET AUTO_CLOSE ON \r\n","GO\r\n","ALTER DATABASE
[Refricentro_Bernardo1] SET AUTO_SHRINK OFF \r\n","GO\r\n","ALTER DATABASE
[Refricentro_Bernardo1] SET AUTO_UPDATE_STATISTICS ON \r\n","GO\r\n","ALTER
DATABASE [Refricentro_Bernardo1] SET CURSOR_CLOSE_ON_COMMIT OFF \r\n","GO\r\
n","ALTER DATABASE [Refricentro_Bernardo1] SET CURSOR_DEFAULT GLOBAL \r\n","GO\r\
n","ALTER DATABASE [Refricentro_Bernardo1] SET CONCAT_NULL_YIELDS_NULL OFF \r\
n","GO\r\n","ALTER DATABASE [Refricentro_Bernardo1] SET NUMERIC_ROUNDABORT OFF \r\
n","GO\r\n","ALTER DATABASE [Refricentro_Bernardo1] SET QUOTED_IDENTIFIER OFF \r\
n","GO\r\n","ALTER DATABASE [Refricentro_Bernardo1] SET RECURSIVE_TRIGGERS OFF \r\
n","GO\r\n","ALTER DATABASE [Refricentro_Bernardo1] SET ENABLE_BROKER \r\n","GO\r\
n","ALTER DATABASE [Refricentro_Bernardo1] SET AUTO_UPDATE_STATISTICS_ASYNC OFF \r\
n","GO\r\n","ALTER DATABASE [Refricentro_Bernardo1] SET
DATE_CORRELATION_OPTIMIZATION OFF \r\n","GO\r\n","ALTER DATABASE
[Refricentro_Bernardo1] SET TRUSTWORTHY OFF \r\n","GO\r\n","ALTER DATABASE
[Refricentro_Bernardo1] SET ALLOW_SNAPSHOT_ISOLATION OFF \r\n","GO\r\n","ALTER
DATABASE [Refricentro_Bernardo1] SET PARAMETERIZATION SIMPLE \r\n","GO\r\n","ALTER
DATABASE [Refricentro_Bernardo1] SET READ_COMMITTED_SNAPSHOT OFF \r\n","GO\r\
n","ALTER DATABASE [Refricentro_Bernardo1] SET HONOR_BROKER_PRIORITY OFF \r\n","GO\
r\n","ALTER DATABASE [Refricentro_Bernardo1] SET RECOVERY SIMPLE \r\n","GO\r\
n","ALTER DATABASE [Refricentro_Bernardo1] SET MULTI_USER \r\n","GO\r\n","ALTER
DATABASE [Refricentro_Bernardo1] SET PAGE_VERIFY CHECKSUM \r\n","GO\r\n","ALTER
DATABASE [Refricentro_Bernardo1] SET DB_CHAINING OFF \r\n","GO\r\n","ALTER DATABASE
[Refricentro_Bernardo1] SET FILESTREAM( NON_TRANSACTED_ACCESS = OFF ) \r\n","GO\r\
n","ALTER DATABASE [Refricentro_Bernardo1] SET TARGET_RECOVERY_TIME = 60 SECONDS \
r\n","GO\r\n","ALTER DATABASE [Refricentro_Bernardo1] SET DELAYED_DURABILITY =
DISABLED \r\n","GO\r\n","ALTER DATABASE [Refricentro_Bernardo1] SET
ACCELERATED_DATABASE_RECOVERY = OFF \r\n","GO\r\n","ALTER DATABASE
[Refricentro_Bernardo1] SET QUERY_STORE = OFF\r\n","GO\r\n"],"metadata":
{"urn":"Server[@Name='DESKTOP-PEKDQ0L\\SQLEXPRESS']/
Database[@Name='Refricentro_Bernardo1']","object_type":"Database"}},
{"cell_type":"markdown","source":["# [dbo].[Sector]"],"metadata":
{"urn":"Server[@Name='DESKTOP-PEKDQ0L\\SQLEXPRESS']/
Database[@Name='Refricentro_Bernardo1']/Table[@Name='Sector' and
@Schema='dbo']","object_type":"Table"}},{"outputs":
[],"execution_count":0,"cell_type":"code","source":["USE [Refricentro_Bernardo1]\r\
n","GO\r\n"],"metadata":{"urn":"Server[@Name='DESKTOP-PEKDQ0L\\SQLEXPRESS']/
Database[@Name='Refricentro_Bernardo1']/Table[@Name='Sector' and
@Schema='dbo']","object_type":"Table"}},{"outputs":
[],"execution_count":0,"cell_type":"code","source":["/****** Object: Table [dbo].
[Sector] Script Date: 25/08/2022 19:46:24 ******/\r\nSET ANSI_NULLS ON\r\n","GO\
r\n","SET QUOTED_IDENTIFIER ON\r\n","GO\r\n","CREATE TABLE [dbo].[Sector](\r\n\
t[Id] [int] NOT NULL,\r\n\t[Descripcion_Sector] [varchar](50) NULL,\r\nPRIMARY KEY
CLUSTERED \r\n(\r\n\t[Id] ASC\r\n)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]\r\n) ON [PRIMARY]\r\nGO\r\
n"],"metadata":{"urn":"Server[@Name='DESKTOP-PEKDQ0L\\SQLEXPRESS']/
Database[@Name='Refricentro_Bernardo1']/Table[@Name='Sector' and
@Schema='dbo']","object_type":"Table"}},{"cell_type":"markdown","source":["# [dbo].
[Municipio]"],"metadata":{"urn":"Server[@Name='DESKTOP-PEKDQ0L\\SQLEXPRESS']/
Database[@Name='Refricentro_Bernardo1']/Table[@Name='Municipio' and
@Schema='dbo']","object_type":"Table"}},{"outputs":
[],"execution_count":0,"cell_type":"code","source":["/****** Object: Table [dbo].
[Municipio] Script Date: 25/08/2022 19:46:24 ******/\r\nSET ANSI_NULLS ON\r\
n","GO\r\n","SET QUOTED_IDENTIFIER ON\r\n","GO\r\n","CREATE TABLE [dbo].[Municipio]
(\r\n\t[Id] [int] NOT NULL,\r\n\t[Descripcion_Municipio] [varchar](50) NULL,\r\n\
t[Id_Sector] [int] NULL,\r\nPRIMARY KEY CLUSTERED \r\n(\r\n\t[Id] ASC\r\n)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]\r\n) ON [PRIMARY]\r\nGO\r\n"],"metadata":{"urn":"Server[@Name='DESKTOP-
PEKDQ0L\\SQLEXPRESS']/Database[@Name='Refricentro_Bernardo1']/
Table[@Name='Municipio' and @Schema='dbo']","object_type":"Table"}},
{"cell_type":"markdown","source":["# [dbo].[Provincia]"],"metadata":
{"urn":"Server[@Name='DESKTOP-PEKDQ0L\\SQLEXPRESS']/
Database[@Name='Refricentro_Bernardo1']/Table[@Name='Provincia' and
@Schema='dbo']","object_type":"Table"}},{"outputs":
[],"execution_count":0,"cell_type":"code","source":["/****** Object: Table [dbo].
[Provincia] Script Date: 25/08/2022 19:46:24 ******/\r\nSET ANSI_NULLS ON\r\
n","GO\r\n","SET QUOTED_IDENTIFIER ON\r\n","GO\r\n","CREATE TABLE [dbo].[Provincia]
(\r\n\t[Id] [int] NOT NULL,\r\n\t[Descripcion_Provincia] [varchar](50) NULL,\r\n\
t[Id_Municipio] [int] NULL,\r\nPRIMARY KEY CLUSTERED \r\n(\r\n\t[Id] ASC\r\n)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]\r\n) ON [PRIMARY]\r\nGO\r\n"],"metadata":{"urn":"Server[@Name='DESKTOP-
PEKDQ0L\\SQLEXPRESS']/Database[@Name='Refricentro_Bernardo1']/
Table[@Name='Provincia' and @Schema='dbo']","object_type":"Table"}},
{"cell_type":"markdown","source":["# [dbo].[Region]"],"metadata":
{"urn":"Server[@Name='DESKTOP-PEKDQ0L\\SQLEXPRESS']/
Database[@Name='Refricentro_Bernardo1']/Table[@Name='Region' and
@Schema='dbo']","object_type":"Table"}},{"outputs":
[],"execution_count":0,"cell_type":"code","source":["/****** Object: Table [dbo].
[Region] Script Date: 25/08/2022 19:46:24 ******/\r\nSET ANSI_NULLS ON\r\n","GO\
r\n","SET QUOTED_IDENTIFIER ON\r\n","GO\r\n","CREATE TABLE [dbo].[Region](\r\n\
t[Id] [int] NOT NULL,\r\n\t[Descripcion_Region] [varchar](50) NULL,\r\n\
t[Id_Provincia] [int] NULL,\r\nPRIMARY KEY CLUSTERED \r\n(\r\n\t[Id] ASC\r\n)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]\r\n) ON [PRIMARY]\r\nGO\r\n"],"metadata":{"urn":"Server[@Name='DESKTOP-
PEKDQ0L\\SQLEXPRESS']/Database[@Name='Refricentro_Bernardo1']/Table[@Name='Region'
and @Schema='dbo']","object_type":"Table"}},{"cell_type":"markdown","source":["#
[dbo].[Clientes]"],"metadata":{"urn":"Server[@Name='DESKTOP-PEKDQ0L\\SQLEXPRESS']/
Database[@Name='Refricentro_Bernardo1']/Table[@Name='Clientes' and
@Schema='dbo']","object_type":"Table"}},{"outputs":
[],"execution_count":0,"cell_type":"code","source":["/****** Object: Table [dbo].
[Clientes] Script Date: 25/08/2022 19:46:24 ******/\r\nSET ANSI_NULLS ON\r\
n","GO\r\n","SET QUOTED_IDENTIFIER ON\r\n","GO\r\n","CREATE TABLE [dbo].[Clientes]
(\r\n\t[Customer_Id] [int] NOT NULL,\r\n\t[Nombre] [varchar](50) NOT NULL,\r\n\
t[Apellidos] [varchar](20) NOT NULL,\r\n\t[FechaNacimiento] [datetime] NULL,\r\n\
t[Direccion] [varchar](75) NULL,\r\n\t[Telefono] [varchar](25) NULL,\r\n\
t[Id_Region] [int] NULL,\r\n\t[Email] [varchar](100) NULL,\r\n\t[Fecha_Creacion]
[datetime] NULL,\r\nPRIMARY KEY CLUSTERED \r\n(\r\n\t[Customer_Id] ASC\r\n)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]\r\n) ON [PRIMARY]\r\nGO\r\n"],"metadata":{"urn":"Server[@Name='DESKTOP-
PEKDQ0L\\SQLEXPRESS']/Database[@Name='Refricentro_Bernardo1']/
Table[@Name='Clientes' and @Schema='dbo']","object_type":"Table"}},
{"cell_type":"markdown","source":["# [dbo].[Producto]"],"metadata":
{"urn":"Server[@Name='DESKTOP-PEKDQ0L\\SQLEXPRESS']/
Database[@Name='Refricentro_Bernardo1']/Table[@Name='Producto'
and @Schema='dbo']","object_type":"Table"}},{"outputs":
[],"execution_count":0,"cell_type":"code","source":["/****** Object: Table [dbo].
[Producto] Script Date: 25/08/2022 19:46:24 ******/\r\nSET ANSI_NULLS ON\r\
n","GO\r\n","SET QUOTED_IDENTIFIER ON\r\n","GO\r\n","CREATE TABLE [dbo].[Producto]
(\r\n\t[Id_Producto] [int] NOT NULL,\r\n\t[Descripcion_Producto] [varchar](100)
NULL,\r\n\t[Modelo] [varchar](25) NULL,\r\n\t[Precio] [decimal](10, 2) NULL,\r\
nPRIMARY KEY CLUSTERED \r\n(\r\n\t[Id_Producto] ASC\r\n)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]\r\n) ON
[PRIMARY]\r\nGO\r\n"],"metadata":{"urn":"Server[@Name='DESKTOP-PEKDQ0L\\
SQLEXPRESS']/Database[@Name='Refricentro_Bernardo1']/Table[@Name='Producto' and
@Schema='dbo']","object_type":"Table"}},{"cell_type":"markdown","source":["# [dbo].
[Roles]"],"metadata":{"urn":"Server[@Name='DESKTOP-PEKDQ0L\\SQLEXPRESS']/
Database[@Name='Refricentro_Bernardo1']/Table[@Name='Roles' and
@Schema='dbo']","object_type":"Table"}},{"outputs":
[],"execution_count":0,"cell_type":"code","source":["/****** Object: Table [dbo].
[Roles] Script Date: 25/08/2022 19:46:24 ******/\r\nSET ANSI_NULLS ON\r\n","GO\
r\n","SET QUOTED_IDENTIFIER ON\r\n","GO\r\n","CREATE TABLE [dbo].[Roles](\r\n\t[Id]
[int] NOT NULL,\r\n\t[Descripcion_Rol] [varchar](25) NULL,\r\nPRIMARY KEY CLUSTERED
\r\n(\r\n\t[Id] ASC\r\n)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]\r\n) ON [PRIMARY]\r\nGO\r\
n"],"metadata":{"urn":"Server[@Name='DESKTOP-PEKDQ0L\\SQLEXPRESS']/
Database[@Name='Refricentro_Bernardo1']/Table[@Name='Roles' and
@Schema='dbo']","object_type":"Table"}},{"cell_type":"markdown","source":["# [dbo].
[Empleado]"],"metadata":{"urn":"Server[@Name='DESKTOP-PEKDQ0L\\SQLEXPRESS']/
Database[@Name='Refricentro_Bernardo1']/Table[@Name='Empleado' and
@Schema='dbo']","object_type":"Table"}},{"outputs":
[],"execution_count":0,"cell_type":"code","source":["/****** Object: Table [dbo].
[Empleado] Script Date: 25/08/2022 19:46:24 ******/\r\nSET ANSI_NULLS ON\r\
n","GO\r\n","SET QUOTED_IDENTIFIER ON\r\n","GO\r\n","CREATE TABLE [dbo].[Empleado]
(\r\n\t[Empleado_Id] [int] NOT NULL,\r\n\t[Nombre] [varchar](50) NOT NULL,\r\n\
t[Apellidos] [varchar](20) NOT NULL,\r\n\t[FechaNacimiento] [datetime] NULL,\r\n\
t[Direccion] [varchar](75) NULL,\r\n\t[Telefono] [varchar](25) NULL,\r\n\
t[Id_Region] [int] NULL,\r\n\t[Email] [varchar](100) NULL,\r\n\t[Fecha_Creacion]
[datetime] NULL,\r\n\t[Id_Rol] [int] NULL,\r\n\t[Id_Departamento] [int] NULL,\r\
nPRIMARY KEY CLUSTERED \r\n(\r\n\t[Empleado_Id] ASC\r\n)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]\r\n) ON
[PRIMARY]\r\nGO\r\n"],"metadata":{"urn":"Server[@Name='DESKTOP-PEKDQ0L\\
SQLEXPRESS']/Database[@Name='Refricentro_Bernardo1']/Table[@Name='Empleado' and
@Schema='dbo']","object_type":"Table"}},{"cell_type":"markdown","source":["# [dbo].
[Factura]"],"metadata":{"urn":"Server[@Name='DESKTOP-PEKDQ0L\\SQLEXPRESS']/
Database[@Name='Refricentro_Bernardo1']/Table[@Name='Factura' and
@Schema='dbo']","object_type":"Table"}},{"outputs":
[],"execution_count":0,"cell_type":"code","source":["/****** Object: Table [dbo].
[Factura] Script Date: 25/08/2022 19:46:24 ******/\r\nSET ANSI_NULLS ON\r\
n","GO\r\n","SET QUOTED_IDENTIFIER ON\r\n","GO\r\n","CREATE TABLE [dbo].[Factura](\
r\n\t[Factura_Id] [int] NOT NULL,\r\n\t[Customer_Id] [int] NULL,\r\n\t[Id_Producto]
[int] NULL,\r\n\t[Fecha_Compra] [datetime] NULL,\r\n\t[Cantidad] [int] NULL,\r\n\
t[Total_Compra] [decimal](10, 2) NULL,\r\n\t[Id_Empleado] [int] NULL,\r\nPRIMARY
KEY CLUSTERED \r\n(\r\n\t[Factura_Id] ASC\r\n)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]\r\n) ON
[PRIMARY]\r\nGO\r\n"],"metadata":{"urn":"Server[@Name='DESKTOP-PEKDQ0L\\
SQLEXPRESS']/Database[@Name='Refricentro_Bernardo1']/Table[@Name='Factura' and
@Schema='dbo']","object_type":"Table"}},{"cell_type":"markdown","source":["# [dbo].
[vwVentas]"],"metadata":{"urn":"Server[@Name='DESKTOP-PEKDQ0L\\SQLEXPRESS']/
Database[@Name='Refricentro_Bernardo1']/View[@Name='vwVentas' and
@Schema='dbo']","object_type":"View"}},{"outputs":
[],"execution_count":0,"cell_type":"code","source":["/****** Object: View [dbo].
[vwVentas] Script Date: 25/08/2022 19:46:24 ******/\r\nSET ANSI_NULLS ON\r\
n","GO\r\n","SET QUOTED_IDENTIFIER ON\r\n","GO\r\n","Create View [dbo].[vwVentas]
as\r\nSelect C.Customer_Id, C.Nombre + ' ' + C.Apellidos as Cliente, C.Direccion,
C.Telefono,\r\nR.Descripcion_Region as Region, P.Descripcion_Provincia as
Provincia,\r\nM.Descripcion_Municipio as Municipio, S.Descripcion_Sector as Sector,
C.Email,\r\nPR.Id_Producto as Codigo, PR.Descripcion_Producto as Producto,
PR.Modelo,\r\nPR.Precio, F.Cantidad, F.Total_Compra, F.Fecha_Compra, E.Nombre + ' '
+ E.Apellidos as\r\nEmpleado, RL.Descripcion_rol as Posicion\r\nFrom Factura F\r\
nJoin Clientes C on (F.Customer_Id = C.Customer_Id)\r\nJoin Region R on
(C.Id_Region = R.Id)\r\nJoin Provincia P on (R.Id_Provincia = P.Id)\r\nJoin
Municipio M on (P.Id_Municipio = M.Id)\r\nJoin Sector S on (M.Id_Sector = S.Id)\r\
nJoin Producto PR on (F.Id_Producto = PR.Id_Producto)\r\nJoin Empleado E on
(F.Id_Empleado = E.Empleado_Id)\r\nJoin Roles RL on (E.Id_Rol = RL.Id)\r\n","GO\r\
n"],"metadata":{"urn":"Server[@Name='DESKTOP-PEKDQ0L\\SQLEXPRESS']/
Database[@Name='Refricentro_Bernardo1']/View[@Name='vwVentas' and
@Schema='dbo']","object_type":"View"}},{"cell_type":"markdown","source":["# [dbo].
[Departamento]"],"metadata":{"urn":"Server[@Name='DESKTOP-PEKDQ0L\\SQLEXPRESS']/
Database[@Name='Refricentro_Bernardo1']/Table[@Name='Departamento' and
@Schema='dbo']","object_type":"Table"}},{"outputs":
[],"execution_count":0,"cell_type":"code","source":["/****** Object: Table [dbo].
[Departamento] Script Date: 25/08/2022 19:46:24 ******/\r\nSET ANSI_NULLS ON\r\
n","GO\r\n","SET QUOTED_IDENTIFIER ON\r\n","GO\r\n","CREATE TABLE [dbo].
[Departamento](\r\n\t[Id] [int] NOT NULL,\r\n\t[Descripcion_Departamento] [varchar]
(50) NULL,\r\nPRIMARY KEY CLUSTERED \r\n(\r\n\t[Id] ASC\r\n)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]\r\n) ON
[PRIMARY]\r\nGO\r\n"],"metadata":{"urn":"Server[@Name='DESKTOP-PEKDQ0L\\
SQLEXPRESS']/Database[@Name='Refricentro_Bernardo1']/Table[@Name='Departamento' and
@Schema='dbo']","object_type":"Table"}},{"cell_type":"markdown","source":["#
[Fk_Region]"],"metadata":{"urn":"Server[@Name='DESKTOP-PEKDQ0L\\SQLEXPRESS']/
Database[@Name='Refricentro_Bernardo1']/Table[@Name='Clientes' and
@Schema='dbo']/ForeignKey[@Name='Fk_Region']","object_type":"ForeignKey"}},
{"outputs":[],"execution_count":0,"cell_type":"code","source":["ALTER TABLE [dbo].
[Clientes] WITH CHECK ADD CONSTRAINT [Fk_Region] FOREIGN KEY([Id_Region])\r\
nREFERENCES [dbo].[Region] ([Id])\r\n","GO\r\n","ALTER TABLE [dbo].[Clientes] CHECK
CONSTRAINT [Fk_Region]\r\n","GO\r\n"],"metadata":{"urn":"Server[@Name='DESKTOP-
PEKDQ0L\\SQLEXPRESS']/Database[@Name='Refricentro_Bernardo1']/
Table[@Name='Clientes' and
@Schema='dbo']/ForeignKey[@Name='Fk_Region']","object_type":"ForeignKey"}},
{"cell_type":"markdown","source":["# [Fk_Departamento]"],"metadata":
{"urn":"Server[@Name='DESKTOP-PEKDQ0L\\SQLEXPRESS']/
Database[@Name='Refricentro_Bernardo1']/Table[@Name='Empleado' and
@Schema='dbo']/ForeignKey[@Name='Fk_Departamento']","object_type":"ForeignKey"}},
{"outputs":[],"execution_count":0,"cell_type":"code","source":["ALTER TABLE [dbo].
[Empleado] WITH CHECK ADD CONSTRAINT [Fk_Departamento] FOREIGN
KEY([Id_Departamento])\r\nREFERENCES [dbo].[Departamento] ([Id])\r\n","GO\r\
n","ALTER TABLE [dbo].[Empleado] CHECK CONSTRAINT [Fk_Departamento]\r\n","GO\r\
n"],"metadata":{"urn":"Server[@Name='DESKTOP-PEKDQ0L\\SQLEXPRESS']/
Database[@Name='Refricentro_Bernardo1']/Table[@Name='Empleado' and
@Schema='dbo']/ForeignKey[@Name='Fk_Departamento']","object_type":"ForeignKey"}},
{"cell_type":"markdown","source":["# [Fk_E_Region]"],"metadata":
{"urn":"Server[@Name='DESKTOP-PEKDQ0L\\SQLEXPRESS']/
Database[@Name='Refricentro_Bernardo1']/Table[@Name='Empleado' and
@Schema='dbo']/ForeignKey[@Name='Fk_E_Region']","object_type":"ForeignKey"}},
{"outputs":[],"execution_count":0,"cell_type":"code","source":["ALTER TABLE [dbo].
[Empleado] WITH CHECK ADD CONSTRAINT [Fk_E_Region] FOREIGN KEY([Id_Region])\r\
nREFERENCES [dbo].[Region] ([Id])\r\n","GO\r\n","ALTER TABLE [dbo].[Empleado] CHECK
CONSTRAINT [Fk_E_Region]\r\n","GO\r\n"],"metadata":{"urn":"Server[@Name='DESKTOP-
PEKDQ0L\\SQLEXPRESS']/Database[@Name='Refricentro_Bernardo1']/
Table[@Name='Empleado' and
@Schema='dbo']/ForeignKey[@Name='Fk_E_Region']","object_type":"ForeignKey"}},
{"cell_type":"markdown","source":["# [Fk_Rol]"],"metadata":
{"urn":"Server[@Name='DESKTOP-PEKDQ0L\\SQLEXPRESS']/
Database[@Name='Refricentro_Bernardo1']/Table[@Name='Empleado' and
@Schema='dbo']/ForeignKey[@Name='Fk_Rol']","object_type":"ForeignKey"}},{"outputs":
[],"execution_count":0,"cell_type":"code","source":["ALTER TABLE [dbo].[Empleado]
WITH CHECK ADD CONSTRAINT [Fk_Rol] FOREIGN KEY([Id_Rol])\r\nREFERENCES [dbo].
[Roles] ([Id])\r\n","GO\r\n","ALTER TABLE [dbo].[Empleado] CHECK CONSTRAINT
[Fk_Rol]\r\n","GO\r\n"],"metadata":{"urn":"Server[@Name='DESKTOP-PEKDQ0L\\
SQLEXPRESS']/Database[@Name='Refricentro_Bernardo1']/Table[@Name='Empleado' and
@Schema='dbo']/ForeignKey[@Name='Fk_Rol']","object_type":"ForeignKey"}},
{"cell_type":"markdown","source":["# [Fk_Empleado]"],"metadata":
{"urn":"Server[@Name='DESKTOP-PEKDQ0L\\SQLEXPRESS']/
Database[@Name='Refricentro_Bernardo1']/Table[@Name='Factura'
and @Schema='dbo']/ForeignKey[@Name='Fk_Empleado']","object_type":"ForeignKey"}},
{"outputs":[],"execution_count":0,"cell_type":"code","source":["ALTER TABLE [dbo].
[Factura] WITH CHECK ADD CONSTRAINT [Fk_Empleado] FOREIGN KEY([Id_Empleado])\r\
nREFERENCES [dbo].[Empleado] ([Empleado_Id])\r\n","GO\r\n","ALTER TABLE [dbo].
[Factura] CHECK CONSTRAINT [Fk_Empleado]\r\n","GO\r\n"],"metadata":
{"urn":"Server[@Name='DESKTOP-PEKDQ0L\\SQLEXPRESS']/
Database[@Name='Refricentro_Bernardo1']/Table[@Name='Factura' and
@Schema='dbo']/ForeignKey[@Name='Fk_Empleado']","object_type":"ForeignKey"}},
{"cell_type":"markdown","source":["# [Fk_Producto]"],"metadata":
{"urn":"Server[@Name='DESKTOP-PEKDQ0L\\SQLEXPRESS']/
Database[@Name='Refricentro_Bernardo1']/Table[@Name='Factura' and
@Schema='dbo']/ForeignKey[@Name='Fk_Producto']","object_type":"ForeignKey"}},
{"outputs":[],"execution_count":0,"cell_type":"code","source":["ALTER TABLE [dbo].
[Factura] WITH CHECK ADD CONSTRAINT [Fk_Producto] FOREIGN KEY([Id_Producto])\r\
nREFERENCES [dbo].[Producto] ([Id_Producto])\r\n","GO\r\n","ALTER TABLE [dbo].
[Factura] CHECK CONSTRAINT [Fk_Producto]\r\n","GO\r\n"],"metadata":
{"urn":"Server[@Name='DESKTOP-PEKDQ0L\\SQLEXPRESS']/
Database[@Name='Refricentro_Bernardo1']/Table[@Name='Factura' and
@Schema='dbo']/ForeignKey[@Name='Fk_Producto']","object_type":"ForeignKey"}},
{"cell_type":"markdown","source":["# [Fk_Sector]"],"metadata":
{"urn":"Server[@Name='DESKTOP-PEKDQ0L\\SQLEXPRESS']/
Database[@Name='Refricentro_Bernardo1']/Table[@Name='Municipio' and
@Schema='dbo']/ForeignKey[@Name='Fk_Sector']","object_type":"ForeignKey"}},
{"outputs":[],"execution_count":0,"cell_type":"code","source":["ALTER TABLE [dbo].
[Municipio] WITH CHECK ADD CONSTRAINT [Fk_Sector] FOREIGN KEY([Id_Sector])\r\
nREFERENCES [dbo].[Sector] ([Id])\r\n","GO\r\n","ALTER TABLE [dbo].[Municipio]
CHECK CONSTRAINT [Fk_Sector]\r\n","GO\r\n"],"metadata":
{"urn":"Server[@Name='DESKTOP-PEKDQ0L\\SQLEXPRESS']/
Database[@Name='Refricentro_Bernardo1']/Table[@Name='Municipio' and
@Schema='dbo']/ForeignKey[@Name='Fk_Sector']","object_type":"ForeignKey"}},
{"cell_type":"markdown","source":["# [Fk_Municipio]"],"metadata":
{"urn":"Server[@Name='DESKTOP-PEKDQ0L\\SQLEXPRESS']/
Database[@Name='Refricentro_Bernardo1']/Table[@Name='Provincia' and
@Schema='dbo']/ForeignKey[@Name='Fk_Municipio']","object_type":"ForeignKey"}},
{"outputs":[],"execution_count":0,"cell_type":"code","source":["ALTER TABLE [dbo].
[Provincia] WITH CHECK ADD CONSTRAINT [Fk_Municipio] FOREIGN KEY([Id_Municipio])\
r\nREFERENCES [dbo].[Municipio] ([Id])\r\n","GO\r\n","ALTER TABLE [dbo].[Provincia]
CHECK CONSTRAINT [Fk_Municipio]\r\n","GO\r\n"],"metadata":
{"urn":"Server[@Name='DESKTOP-PEKDQ0L\\SQLEXPRESS']/
Database[@Name='Refricentro_Bernardo1']/Table[@Name='Provincia' and
@Schema='dbo']/ForeignKey[@Name='Fk_Municipio']","object_type":"ForeignKey"}},
{"cell_type":"markdown","source":["# [Fk_Provincia]"],"metadata":
{"urn":"Server[@Name='DESKTOP-PEKDQ0L\\SQLEXPRESS']/
Database[@Name='Refricentro_Bernardo1']/Table[@Name='Region' and
@Schema='dbo']/ForeignKey[@Name='Fk_Provincia']","object_type":"ForeignKey"}},
{"outputs":[],"execution_count":0,"cell_type":"code","source":["ALTER TABLE [dbo].
[Region] WITH CHECK ADD CONSTRAINT [Fk_Provincia] FOREIGN KEY([Id_Provincia])\r\
nREFERENCES [dbo].[Provincia] ([Id])\r\n","GO\r\n","ALTER TABLE [dbo].[Region]
CHECK CONSTRAINT [Fk_Provincia]\r\n","GO\r\n"],"metadata":
{"urn":"Server[@Name='DESKTOP-PEKDQ0L\\SQLEXPRESS']/
Database[@Name='Refricentro_Bernardo1']/Table[@Name='Region' and
@Schema='dbo']/ForeignKey[@Name='Fk_Provincia']","object_type":"ForeignKey"}},
{"cell_type":"markdown","source":["# [dbo].[SP_Datos_Clientes]"],"metadata":
{"urn":"Server[@Name='DESKTOP-PEKDQ0L\\SQLEXPRESS']/
Database[@Name='Refricentro_Bernardo1']/StoredProcedure[@Name='SP_Datos_Clientes'
and @Schema='dbo']","object_type":"StoredProcedure"}},{"outputs":
[],"execution_count":0,"cell_type":"code","source":["/****** Object:
StoredProcedure [dbo].[SP_Datos_Clientes] Script Date: 25/08/2022 19:46:24
******/\r\nSET ANSI_NULLS ON\r\n","GO\r\n","SET QUOTED_IDENTIFIER ON\r\n","GO\r\
n","Create Proc [dbo].[SP_Datos_Clientes]\r\n@Id_Cliente int As\r\nSelect Cliente,
Direccion, Telefono, Region, Provincia, Municipio, Sector, Email\r\nFrom vwVentas\
r\nWhere Customer_Id = @Id_Cliente\r\nExecute SP_Datos_Clientes 001\r\n","GO\r\
n"],"metadata":{"urn":"Server[@Name='DESKTOP-PEKDQ0L\\SQLEXPRESS']/
Database[@Name='Refricentro_Bernardo1']/StoredProcedure[@Name='SP_Datos_Clientes'
and @Schema='dbo']","object_type":"StoredProcedure"}},
{"cell_type":"markdown","source":["# [dbo].[SP_Monto]"],"metadata":
{"urn":"Server[@Name='DESKTOP-PEKDQ0L\\SQLEXPRESS']/
Database[@Name='Refricentro_Bernardo1']/StoredProcedure[@Name='SP_Monto' and
@Schema='dbo']","object_type":"StoredProcedure"}},{"outputs":
[],"execution_count":0,"cell_type":"code","source":["/****** Object:
StoredProcedure [dbo].[SP_Monto] Script Date: 25/08/2022 19:46:24 ******/\r\nSET
ANSI_NULLS ON\r\n","GO\r\n","SET QUOTED_IDENTIFIER ON\r\n","GO\r\n","Create Proc
[dbo].[SP_Monto]\r\n@Id_Cliente int As\r\nSelect Cliente, Count (*) as Compras,\r\
nSUM (Total_Compra) Total_Compra from vwVentas\r\nWhere Customer_Id = @Id_Cliente\
r\nGroup By Cliente\r\n","GO\r\n"],"metadata":{"urn":"Server[@Name='DESKTOP-
PEKDQ0L\\SQLEXPRESS']/Database[@Name='Refricentro_Bernardo1']/
StoredProcedure[@Name='SP_Monto' and
@Schema='dbo']","object_type":"StoredProcedure"}},{"cell_type":"markdown","source":
["# [Refricentro_Bernardo1]"],"metadata":{"urn":"Server[@Name='DESKTOP-PEKDQ0L\\
SQLEXPRESS']/Database[@Name='Refricentro_Bernardo1']","object_type":"Database"}},
{"outputs":[],"execution_count":0,"cell_type":"code","source":["USE [master]\r\
n","GO\r\n"],"metadata":{"urn":"Server[@Name='DESKTOP-PEKDQ0L\\SQLEXPRESS']/
Database[@Name='Refricentro_Bernardo1']","object_type":"Database"}},{"outputs":
[],"execution_count":0,"cell_type":"code","source":["ALTER DATABASE
[Refricentro_Bernardo1] SET READ_WRITE \r\n","GO\r\n"],"metadata":
{"urn":"Server[@Name='DESKTOP-PEKDQ0L\\SQLEXPRESS']/
Database[@Name='Refricentro_Bernardo1']","object_type":"Database"}}]}

You might also like