Você está na página 1de 19

SE [dbventas]

GO
/****** Object: Table [dbo].[cliente] Script Date: 03/15/2018 09:36:30 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[cliente](
[idcliente] [int] IDENTITY(1,1) NOT NULL,
[nombres] [varchar](50) NOT NULL,
[apellidos] [varchar](50) NOT NULL,
[direccion] [varchar](100) NOT NULL,
[telefono] [varchar](10) NOT NULL,
[dni] [varchar](8) NOT NULL,
CONSTRAINT [PK_cliente] PRIMARY KEY CLUSTERED
(
[idcliente] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF,
ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
/****** Object: Table [dbo].[categoria] Script Date: 03/15/2018 09:36:30
******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[categoria](
[idcategoria] [int] IDENTITY(1,1) NOT NULL,
[nombre_categoria] [varchar](50) NOT NULL,
CONSTRAINT [PK_categoria] PRIMARY KEY CLUSTERED
(
[idcategoria] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF,
ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
/****** Object: StoredProcedure [dbo].[backup_base] Script Date: 03/15/2018
09:36:31 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create proc [dbo].[backup_base]
as
BACKUP DATABASE [dbventas]
TO DISK =N'D:\Sisventas\BaseDatos\dbventas.bak'
WITH DESCRIPTION=N'Respaldo de la base de datos del Sistema de Ventas',
NOFORMAT,
INIT,
NAME=N'dbventas',
SKIP,
NOREWIND,
NOUNLOAD,
STATS=10,
CHECKSUM
GO
/****** Object: Table [dbo].[usuario] Script Date: 03/15/2018 09:36:31 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[usuario](
[idusuario] [int] IDENTITY(1,1) NOT NULL,
[nombre] [varchar](50) NOT NULL,
[apellidos] [varchar](50) NOT NULL,
[dni] [varchar](8) NOT NULL,
[direccion] [varchar](100) NOT NULL,
[telefono] [varchar](10) NOT NULL,
[login] [varchar](50) NOT NULL,
[password] [varchar](50) NOT NULL,
[acceso] [varchar](1) NOT NULL,
CONSTRAINT [PK_usuario] PRIMARY KEY CLUSTERED
(
[idusuario] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF,
ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
/****** Object: Table [dbo].[venta] Script Date: 03/15/2018 09:36:31 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[venta](
[idventa] [int] IDENTITY(1,1) NOT NULL,
[idcliente] [int] NOT NULL,
[fecha_venta] [date] NOT NULL,
[tipo_documento] [varchar](50) NOT NULL,
[num_documento] [varchar](50) NOT NULL,
CONSTRAINT [PK_venta] PRIMARY KEY CLUSTERED
(
[idventa] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF,
ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
/****** Object: StoredProcedure [dbo].[validar_usuario] Script Date: 03/15/2018
09:36:31 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create proc [dbo].[validar_usuario]

@login varchar(50),
@password varchar(50)
as

select * from usuario

where login=@login and password=@password and acceso='1'


GO
/****** Object: StoredProcedure [dbo].[mostrar_usuario] Script Date: 03/15/2018
09:36:31 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create proc [dbo].[mostrar_usuario]
as
select * from usuario order by idusuario desc
GO
/****** Object: StoredProcedure [dbo].[insertar_usuario] Script Date:
03/15/2018 09:36:31 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create proc [dbo].[insertar_usuario]
@nombre varchar(50),
@apellidos varchar(50),
@dni varchar(8),
@direccion varchar(100),
@telefono varchar(10),
@login varchar(50),
@password varchar(50),
@acceso varchar(50)

as

insert into usuario (nombre,apellidos,dni,direccion,telefono,login,password,acceso)


values (@nombre,@apellidos,@dni,@direccion,@telefono,@login,@password,@acceso)
GO
/****** Object: StoredProcedure [dbo].[mostrar_cliente] Script Date: 03/15/2018
09:36:31 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create proc [dbo].[mostrar_cliente]
as
select * from cliente order by idcliente desc
GO
/****** Object: StoredProcedure [dbo].[mostrar_categoria] Script Date:
03/15/2018 09:36:31 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create proc [dbo].[mostrar_categoria]
as
select * from categoria order by idcategoria desc
GO
/****** Object: Table [dbo].[producto] Script Date: 03/15/2018 09:36:31 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[producto](
[idproducto] [int] IDENTITY(1,1) NOT NULL,
[idcategoria] [int] NOT NULL,
[nombre] [varchar](50) NOT NULL,
[descripcion] [varchar](255) NOT NULL,
[stock] [decimal](18, 2) NOT NULL,
[precio_compra] [decimal](18, 2) NOT NULL,
[precio_venta] [decimal](18, 2) NOT NULL,
[fecha_vencimiento] [date] NOT NULL,
[imagen] [image] NULL,
CONSTRAINT [PK_producto] PRIMARY KEY CLUSTERED
(
[idproducto] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF,
ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
/****** Object: StoredProcedure [dbo].[insertar_cliente] Script Date:
03/15/2018 09:36:31 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE proc [dbo].[insertar_cliente]
@nombres varchar(50),
@apellidos varchar(50),
@direccion varchar(100),
@telefono varchar(10),
@dni varchar(8)
as

insert into cliente (nombres,apellidos,direccion,telefono,dni) values


(@nombres,@apellidos,@direccion,@telefono,@dni)
GO
/****** Object: StoredProcedure [dbo].[insertar_categoria] Script Date:
03/15/2018 09:36:31 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create proc [dbo].[insertar_categoria]
@nombre_categoria varchar(50)
as
insert into categoria (nombre_categoria) values (@nombre_categoria)
GO
/****** Object: StoredProcedure [dbo].[eliminar_usuario] Script Date:
03/15/2018 09:36:31 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create proc [dbo].[eliminar_usuario]

@idusuario integer
as
delete from usuario where idusuario=@idusuario
GO
/****** Object: StoredProcedure [dbo].[editar_usuario] Script Date: 03/15/2018
09:36:31 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create proc [dbo].[editar_usuario]

@idusuario integer,
@nombre varchar(50),
@apellidos varchar(50),
@dni varchar(8),
@direccion varchar (100),
@telefono varchar(9),
@login varchar(50),
@password varchar(50),
@acceso varchar(1)
as update usuario set nombre=@nombre,apellidos =
@apellidos,dni=@dni,direccion=@direccion,telefono=@telefono ,login=@login,password
=@password,acceso=@acceso
where idusuario =@idusuario
GO
/****** Object: StoredProcedure [dbo].[eliminar_cliente] Script Date:
03/15/2018 09:36:31 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create proc [dbo].[eliminar_cliente]
@idcliente integer

as

delete from cliente where idcliente = @idcliente


GO
/****** Object: StoredProcedure [dbo].[eliminar_categoria] Script Date:
03/15/2018 09:36:31 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create proc [dbo].[eliminar_categoria]
@idcategoria integer
as
delete from categoria where idcategoria = @idcategoria
GO
/****** Object: StoredProcedure [dbo].[editar_cliente] Script Date: 03/15/2018
09:36:31 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE proc [dbo].[editar_cliente]

@idcliente integer,
@nombres varchar(50),
@apellidos varchar(50),
@direccion varchar(100),
@telefono varchar(9),
@dni varchar(8)

as

update cliente set nombres = @nombres, apellidos = @apellidos, direccion =


@direccion, telefono = @telefono , dni = @dni

where idcliente= @idcliente


GO
/****** Object: StoredProcedure [dbo].[editar_categoria] Script Date:
03/15/2018 09:36:31 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create proc [dbo].[editar_categoria]
@idcategoria integer,
@nombre_categoria varchar(50)
as
update categoria set nombre_categoria=@nombre_categoria
where idcategoria=@idcategoria
GO
/****** Object: StoredProcedure [dbo].[aumentar_stock] Script Date: 03/15/2018
09:36:31 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create proc [dbo].[aumentar_stock]
@idproducto as integer,
@cantidad as decimal(18,2)
as
update producto set stock=stock+@cantidad where idproducto=@idproducto
GO
/****** Object: StoredProcedure [dbo].[disminuir_stock] Script Date: 03/15/2018
09:36:31 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create proc [dbo].[disminuir_stock]
@idproducto as integer,
@cantidad as decimal(18,2)
as
update producto set stock=stock-@cantidad where idproducto=@idproducto
GO
/****** Object: Table [dbo].[detalle_venta] Script Date: 03/15/2018 09:36:31
******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[detalle_venta](
[iddetalle_venta] [int] IDENTITY(1,1) NOT NULL,
[idventa] [int] NOT NULL,
[idproducto] [int] NOT NULL,
[cantidad] [decimal](18, 2) NOT NULL,
[precio_unitario] [decimal](18, 2) NOT NULL,
CONSTRAINT [PK_detalle_venta] PRIMARY KEY CLUSTERED
(
[iddetalle_venta] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF,
ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object: StoredProcedure [dbo].[editar_venta] Script Date: 03/15/2018
09:36:31 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create proc [dbo].[editar_venta]

@idventa as integer,
@idcliente as integer,
@fecha_venta as date,
@tipo_documento as varchar(50),
@num_documento as varchar(50)

as

update venta set


idcliente=@idcliente,fecha_venta=@fecha_venta,tipo_documento=@tipo_documento,num_do
cumento=@num_documento

where idventa=@idventa
GO
/****** Object: StoredProcedure [dbo].[editar_producto] Script Date: 03/15/2018
09:36:31 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create proc [dbo].[editar_producto]
@idproducto integer,
@idcategoria integer,
@nombre varchar(50),
@descripcion varchar(50),
@stock decimal(18,2),
@precio_compra decimal(18,2),
@precio_venta decimal(18,2),
@fecha_vencimiento date,
@imagen image
as update producto set
idcategoria=@idcategoria,nombre=@nombre,descripcion=@descripcion,stock=@stock,preci
o_compra=@precio_compra,precio_venta=@precio_venta,fecha_vencimiento=@fecha_vencimi
ento,imagen=@imagen
where idproducto=@idproducto
GO
/****** Object: StoredProcedure [dbo].[eliminar_producto] Script Date:
03/15/2018 09:36:31 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create proc [dbo].[eliminar_producto]
@idproducto integer
as
delete from producto where idproducto=@idproducto
GO
/****** Object: StoredProcedure [dbo].[mostrar_venta] Script Date: 03/15/2018
09:36:31 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE proc [dbo].[mostrar_venta]
as
SELECT dbo.venta.idventa, dbo.venta.idcliente, dbo.cliente.apellidos,
dbo.cliente.dni, dbo.venta.fecha_venta, dbo.venta.tipo_documento,
dbo.venta.num_documento
FROM dbo.cliente INNER JOIN
dbo.venta ON dbo.cliente.idcliente = dbo.venta.idcliente
order by dbo.venta.idventa desc
GO
/****** Object: StoredProcedure [dbo].[insertar_venta] Script Date: 03/15/2018
09:36:31 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create proc [dbo].[insertar_venta]

@idcliente as integer,
@fecha_venta as date,
@tipo_documento as varchar(50),
@num_documento as varchar(50)

as

insert into venta (idcliente,fecha_venta,tipo_documento,num_documento)

values (@idcliente,@fecha_venta,@tipo_documento,@num_documento)
GO
/****** Object: StoredProcedure [dbo].[insertar_producto] Script Date:
03/15/2018 09:36:31 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create proc [dbo].[insertar_producto]

@idcategoria integer,
@nombre varchar(50),
@descripcion varchar(50),
@stock decimal(18,2),
@precio_compra decimal(18,2),
@precio_venta decimal(18,2),
@fecha_vencimiento date,
@imagen image
as
insert into producto (idcategoria ,nombre,descripcion ,stock
,precio_compra,precio_venta,fecha_vencimiento,imagen ) values (@idcategoria
,@nombre,@descripcion ,@stock
,@precio_compra,@precio_venta,@fecha_vencimiento,@imagen )
GO
/****** Object: View [dbo].[Vista] Script Date: 03/15/2018 09:36:33 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE VIEW [dbo].[Vista]
AS
SELECT dbo.venta.idventa, dbo.venta.idcliente, dbo.cliente.apellidos,
dbo.cliente.dni, dbo.venta.fecha_venta, dbo.venta.tipo_documento,
dbo.venta.num_documento
FROM dbo.cliente INNER JOIN
dbo.venta ON dbo.cliente.idcliente = dbo.venta.idcliente
GO
EXEC sys.sp_addextendedproperty @name=N'MS_DiagramPane1', @value=N'[0E232FF0-B466-
11cf-A24F-00AA00A3EFFF, 1.00]
Begin DesignProperties =
Begin PaneConfigurations =
Begin PaneConfiguration = 0
NumPanes = 4
Configuration = "(H (1[40] 4[20] 2[20] 3) )"
End
Begin PaneConfiguration = 1
NumPanes = 3
Configuration = "(H (1 [50] 4 [25] 3))"
End
Begin PaneConfiguration = 2
NumPanes = 3
Configuration = "(H (1 [50] 2 [25] 3))"
End
Begin PaneConfiguration = 3
NumPanes = 3
Configuration = "(H (4 [30] 2 [40] 3))"
End
Begin PaneConfiguration = 4
NumPanes = 2
Configuration = "(H (1 [56] 3))"
End
Begin PaneConfiguration = 5
NumPanes = 2
Configuration = "(H (2 [66] 3))"
End
Begin PaneConfiguration = 6
NumPanes = 2
Configuration = "(H (4 [50] 3))"
End
Begin PaneConfiguration = 7
NumPanes = 1
Configuration = "(V (3))"
End
Begin PaneConfiguration = 8
NumPanes = 3
Configuration = "(H (1[56] 4[18] 2) )"
End
Begin PaneConfiguration = 9
NumPanes = 2
Configuration = "(H (1 [75] 4))"
End
Begin PaneConfiguration = 10
NumPanes = 2
Configuration = "(H (1[66] 2) )"
End
Begin PaneConfiguration = 11
NumPanes = 2
Configuration = "(H (4 [60] 2))"
End
Begin PaneConfiguration = 12
NumPanes = 1
Configuration = "(H (1) )"
End
Begin PaneConfiguration = 13
NumPanes = 1
Configuration = "(V (4))"
End
Begin PaneConfiguration = 14
NumPanes = 1
Configuration = "(V (2))"
End
ActivePaneConfig = 0
End
Begin DiagramPane =
Begin Origin =
Top = 0
Left = 0
End
Begin Tables =
Begin Table = "cliente"
Begin Extent =
Top = 13
Left = 40
Bottom = 165
Right = 238
End
DisplayFlags = 280
TopColumn = 0
End
Begin Table = "venta"
Begin Extent =
Top = 7
Left = 379
Bottom = 160
Right = 577
End
DisplayFlags = 280
TopColumn = 0
End
End
End
Begin SQLPane =
End
Begin DataPane =
Begin ParameterDefaults = ""
End
End
Begin CriteriaPane =
Begin ColumnWidths = 11
Column = 1440
Alias = 900
Table = 1170
Output = 720
Append = 1400
NewValue = 1170
SortType = 1350
SortOrder = 1410
GroupBy = 1350
Filter = 1350
Or = 1350
Or = 1350
Or = 1350
End
End
End
' , @level0type=N'SCHEMA',@level0name=N'dbo',
@level1type=N'VIEW',@level1name=N'Vista'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_DiagramPaneCount', @value=1 ,
@level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'VIEW',@level1name=N'Vista'
GO
/****** Object: StoredProcedure [dbo].[eliminar_venta] Script Date: 03/15/2018
09:36:33 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create proc [dbo].[eliminar_venta]

@idventa as integer

as

delete from venta where idventa=@idventa


GO
/****** Object: StoredProcedure [dbo].[mostrar_producto] Script Date:
03/15/2018 09:36:33 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create proc [dbo].[mostrar_producto]
as
select
producto.idproducto,producto.idcategoria,categoria.nombre_categoria,producto.nombre
,producto.descripcion
,producto.stock,producto.precio_compra,producto.precio_venta,producto.fecha_vencimi
ento,producto.imagen

from producto inner join categoria on producto.idcategoria=categoria.idcategoria


order by producto.idproducto desc
GO
/****** Object: View [dbo].[Vista10] Script Date: 03/15/2018 09:36:33 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE VIEW [dbo].[Vista10]
AS
SELECT dbo.venta.idventa, dbo.cliente.nombres, dbo.cliente.apellidos,
dbo.cliente.dni, dbo.venta.fecha_venta, dbo.venta.tipo_documento,
dbo.venta.num_documento,
dbo.producto.nombre AS Descripcion,
dbo.detalle_venta.cantidad, dbo.detalle_venta.precio_unitario,
dbo.detalle_venta.cantidad *
dbo.detalle_venta.precio_unitario AS Total_Parcial
FROM dbo.venta INNER JOIN
dbo.detalle_venta ON dbo.venta.idventa =
dbo.detalle_venta.idventa INNER JOIN
dbo.producto ON dbo.detalle_venta.idproducto =
dbo.producto.idproducto INNER JOIN
dbo.cliente ON dbo.venta.idcliente = dbo.cliente.idcliente
GO
EXEC sys.sp_addextendedproperty @name=N'MS_DiagramPane1', @value=N'[0E232FF0-B466-
11cf-A24F-00AA00A3EFFF, 1.00]
Begin DesignProperties =
Begin PaneConfigurations =
Begin PaneConfiguration = 0
NumPanes = 4
Configuration = "(H (1[56] 4[7] 2[15] 3) )"
End
Begin PaneConfiguration = 1
NumPanes = 3
Configuration = "(H (1 [50] 4 [25] 3))"
End
Begin PaneConfiguration = 2
NumPanes = 3
Configuration = "(H (1 [50] 2 [25] 3))"
End
Begin PaneConfiguration = 3
NumPanes = 3
Configuration = "(H (4 [30] 2 [40] 3))"
End
Begin PaneConfiguration = 4
NumPanes = 2
Configuration = "(H (1 [56] 3))"
End
Begin PaneConfiguration = 5
NumPanes = 2
Configuration = "(H (2 [66] 3))"
End
Begin PaneConfiguration = 6
NumPanes = 2
Configuration = "(H (4 [50] 3))"
End
Begin PaneConfiguration = 7
NumPanes = 1
Configuration = "(V (3))"
End
Begin PaneConfiguration = 8
NumPanes = 3
Configuration = "(H (1[56] 4[18] 2) )"
End
Begin PaneConfiguration = 9
NumPanes = 2
Configuration = "(H (1 [75] 4))"
End
Begin PaneConfiguration = 10
NumPanes = 2
Configuration = "(H (1[66] 2) )"
End
Begin PaneConfiguration = 11
NumPanes = 2
Configuration = "(H (4 [60] 2))"
End
Begin PaneConfiguration = 12
NumPanes = 1
Configuration = "(H (1) )"
End
Begin PaneConfiguration = 13
NumPanes = 1
Configuration = "(V (4))"
End
Begin PaneConfiguration = 14
NumPanes = 1
Configuration = "(V (2))"
End
ActivePaneConfig = 0
End
Begin DiagramPane =
Begin Origin =
Top = 0
Left = 0
End
Begin Tables =
Begin Table = "venta"
Begin Extent =
Top = 18
Left = 17
Bottom = 165
Right = 215
End
DisplayFlags = 280
TopColumn = 0
End
Begin Table = "detalle_venta"
Begin Extent =
Top = 0
Left = 282
Bottom = 136
Right = 480
End
DisplayFlags = 280
TopColumn = 0
End
Begin Table = "producto"
Begin Extent =
Top = 8
Left = 534
Bottom = 204
Right = 732
End
DisplayFlags = 280
TopColumn = 0
End
Begin Table = "cliente"
Begin Extent =
Top = 135
Left = 297
Bottom = 261
Right = 495
End
DisplayFlags = 280
TopColumn = 2
End
End
End
Begin SQLPane =
End
Begin DataPane =
Begin ParameterDefaults = ""
End
Begin ColumnWidths = 12
Width = 284
Width = 1500
Width = 1500
Width = 1500
Width = 1500
Width = 1500
Width = 1500
Width = 1500
Width = 1500
Width = 1500
Width = 1500
Width = 1500
End
End
Begin CriteriaPane =
Begin ColumnWidths = 11
Column = 1440
Alias = 900
Table = 1170
Output = 720
Append = 1400
NewValue = 1170
SortType = 1350
SortOrder = 1410
GroupBy = 1350
Filter = 1350' , @level0type=N'SCHEMA',@level0name=N'dbo',
@level1type=N'VIEW',@level1name=N'Vista10'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_DiagramPane2', @value=N'
Or = 1350
Or = 1350
Or = 1350
End
End
End
' , @level0type=N'SCHEMA',@level0name=N'dbo',
@level1type=N'VIEW',@level1name=N'Vista10'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_DiagramPaneCount', @value=2 ,
@level0type=N'SCHEMA',@level0name=N'dbo',
@level1type=N'VIEW',@level1name=N'Vista10'
GO
/****** Object: View [dbo].[vista1] Script Date: 03/15/2018 09:36:33 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE VIEW [dbo].[vista1]
AS
SELECT dbo.detalle_venta.iddetalle_venta, dbo.detalle_venta.idventa,
dbo.detalle_venta.idproducto, dbo.producto.nombre, dbo.detalle_venta.cantidad,
dbo.detalle_venta.precio_unitario
FROM dbo.detalle_venta INNER JOIN
dbo.producto ON dbo.detalle_venta.idproducto =
dbo.producto.idproducto
GO
EXEC sys.sp_addextendedproperty @name=N'MS_DiagramPane1', @value=N'[0E232FF0-B466-
11cf-A24F-00AA00A3EFFF, 1.00]
Begin DesignProperties =
Begin PaneConfigurations =
Begin PaneConfiguration = 0
NumPanes = 4
Configuration = "(H (1[41] 4[2] 2[38] 3) )"
End
Begin PaneConfiguration = 1
NumPanes = 3
Configuration = "(H (1 [50] 4 [25] 3))"
End
Begin PaneConfiguration = 2
NumPanes = 3
Configuration = "(H (1 [50] 2 [25] 3))"
End
Begin PaneConfiguration = 3
NumPanes = 3
Configuration = "(H (4 [30] 2 [40] 3))"
End
Begin PaneConfiguration = 4
NumPanes = 2
Configuration = "(H (1 [56] 3))"
End
Begin PaneConfiguration = 5
NumPanes = 2
Configuration = "(H (2 [66] 3))"
End
Begin PaneConfiguration = 6
NumPanes = 2
Configuration = "(H (4 [50] 3))"
End
Begin PaneConfiguration = 7
NumPanes = 1
Configuration = "(V (3))"
End
Begin PaneConfiguration = 8
NumPanes = 3
Configuration = "(H (1[56] 4[18] 2) )"
End
Begin PaneConfiguration = 9
NumPanes = 2
Configuration = "(H (1 [75] 4))"
End
Begin PaneConfiguration = 10
NumPanes = 2
Configuration = "(H (1[66] 2) )"
End
Begin PaneConfiguration = 11
NumPanes = 2
Configuration = "(H (4 [60] 2))"
End
Begin PaneConfiguration = 12
NumPanes = 1
Configuration = "(H (1) )"
End
Begin PaneConfiguration = 13
NumPanes = 1
Configuration = "(V (4))"
End
Begin PaneConfiguration = 14
NumPanes = 1
Configuration = "(V (2))"
End
ActivePaneConfig = 0
End
Begin DiagramPane =
Begin Origin =
Top = 0
Left = 0
End
Begin Tables =
Begin Table = "detalle_venta"
Begin Extent =
Top = 6
Left = 38
Bottom = 168
Right = 236
End
DisplayFlags = 280
TopColumn = 0
End
Begin Table = "producto"
Begin Extent =
Top = 0
Left = 423
Bottom = 200
Right = 621
End
DisplayFlags = 280
TopColumn = 0
End
End
End
Begin SQLPane =
End
Begin DataPane =
Begin ParameterDefaults = ""
End
End
Begin CriteriaPane =
Begin ColumnWidths = 11
Column = 1440
Alias = 900
Table = 1170
Output = 720
Append = 1400
NewValue = 1170
SortType = 1350
SortOrder = 1410
GroupBy = 1350
Filter = 1350
Or = 1350
Or = 1350
Or = 1350
End
End
End
' , @level0type=N'SCHEMA',@level0name=N'dbo',
@level1type=N'VIEW',@level1name=N'vista1'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_DiagramPaneCount', @value=1 ,
@level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'VIEW',@level1name=N'vista1'
GO
/****** Object: StoredProcedure [dbo].[mostrar_detalle_venta] Script Date:
03/15/2018 09:36:33 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE proc [dbo].[mostrar_detalle_venta]
as

SELECT dbo.detalle_venta.iddetalle_venta, dbo.detalle_venta.idventa,


dbo.detalle_venta.idproducto, dbo.producto.nombre, dbo.detalle_venta.cantidad,
dbo.detalle_venta.precio_unitario
FROM dbo.detalle_venta INNER JOIN
dbo.producto ON dbo.detalle_venta.idproducto =
dbo.producto.idproducto

order by dbo.detalle_venta.iddetalle_venta desc


GO
/****** Object: StoredProcedure [dbo].[insertar_detalle_venta] Script Date:
03/15/2018 09:36:33 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE proc [dbo].[insertar_detalle_venta]

@idventa as integer,
@idproducto as integer,
@cantidad as decimal(18,2),
@precio_unitario as decimal(18,2)
as
insert into detalle_venta (idventa,idproducto,cantidad,precio_unitario)
values (@idventa,@idproducto,@cantidad,@precio_unitario)
GO
/****** Object: StoredProcedure [dbo].[generar_comprobante] Script Date:
03/15/2018 09:36:33 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create proc [dbo].[generar_comprobante]

@idventa int
as
SELECT dbo.venta.idventa, dbo.cliente.nombres, dbo.cliente.apellidos,
dbo.cliente.dni, dbo.venta.fecha_venta, dbo.venta.tipo_documento,
dbo.venta.num_documento,
dbo.producto.nombre AS Descripcion,
dbo.detalle_venta.cantidad, dbo.detalle_venta.precio_unitario,
dbo.detalle_venta.cantidad *
dbo.detalle_venta.precio_unitario AS Total_Parcial
FROM dbo.producto INNER JOIN
dbo.detalle_venta ON dbo.producto.idproducto =
dbo.detalle_venta.idproducto INNER JOIN
dbo.venta ON dbo.detalle_venta.idventa = dbo.venta.idventa
INNER JOIN
dbo.cliente ON dbo.venta.idcliente = dbo.cliente.idcliente

where dbo.venta.idventa=@idventa
GO
/****** Object: StoredProcedure [dbo].[eliminar_detalle_venta] Script Date:
03/15/2018 09:36:33 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create proc [dbo].[eliminar_detalle_venta]

@iddetalle_venta as integer
as
delete from detalle_venta where iddetalle_venta= @iddetalle_venta
GO
/****** Object: StoredProcedure [dbo].[editar_detalle_venta] Script Date:
03/15/2018 09:36:33 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create proc [dbo].[editar_detalle_venta]

@iddetalle_venta as integer,
@idventa as integer,
@idproducto as integer,
@cantidad as decimal(18,2),
@precio_unitario as decimal(18,2)
as
update detalle_venta set
idventa=@idventa,idproducto=@idproducto,cantidad=@cantidad,precio_unitario=@precio_
unitario

where iddetalle_venta=@iddetalle_venta
GO
/****** Object: ForeignKey [FK_venta_cliente] Script Date: 03/15/2018 09:36:31
******/
ALTER TABLE [dbo].[venta] WITH CHECK ADD CONSTRAINT [FK_venta_cliente] FOREIGN
KEY([idcliente])
REFERENCES [dbo].[cliente] ([idcliente])
ON DELETE CASCADE
GO
ALTER TABLE [dbo].[venta] CHECK CONSTRAINT [FK_venta_cliente]
GO
/****** Object: ForeignKey [FK_producto_categoria] Script Date: 03/15/2018
09:36:31 ******/
ALTER TABLE [dbo].[producto] WITH CHECK ADD CONSTRAINT [FK_producto_categoria]
FOREIGN KEY([idcategoria])
REFERENCES [dbo].[categoria] ([idcategoria])
GO
ALTER TABLE [dbo].[producto] CHECK CONSTRAINT [FK_producto_categoria]
GO
/****** Object: ForeignKey [FK_detalle_venta_producto] Script Date: 03/15/2018
09:36:31 ******/
ALTER TABLE [dbo].[detalle_venta] WITH CHECK ADD CONSTRAINT
[FK_detalle_venta_producto] FOREIGN KEY([idproducto])
REFERENCES [dbo].[producto] ([idproducto])
GO
ALTER TABLE [dbo].[detalle_venta] CHECK CONSTRAINT [FK_detalle_venta_producto]
GO
/****** Object: ForeignKey [FK_detalle_venta_venta] Script Date: 03/15/2018
09:36:31 ******/
ALTER TABLE [dbo].[detalle_venta] WITH CHECK ADD CONSTRAINT
[FK_detalle_venta_venta] FOREIGN KEY([idventa])
REFERENCES [dbo].[venta] ([idventa])
ON DELETE CASCADE
GO
ALTER TABLE [dbo].[detalle_venta] CHECK CONSTRAINT [FK_detalle_venta_venta]
GO

Você também pode gostar