Está en la página 1de 3

EJERCICIO APLICATIVO DE LABORATORIO No 1 CREAR UNA BASE DE DATOS CUYO NOMBRE SEA VentasDB CUYO TAMAO INICIAL SEA

DE 50 MB, SU TAMAO MAXIMO SEA DE 500 MB, SU INCREMENTO SEA DE 25 MB, ASI MISMO DEBE TENER UN FILEGROUP POR DEFECTO FG_DatosVentasDB. CREANDO LA BASE DE DATOS CREATE DATABASE VENTASDB ON PRIMARY ( NAME = VentasDB_data, FILENAME = C:\Program Files\Microsoft SQL Server\MSSQL10.MSS QLSERVER\MSSQL\DATA\VentasDB.mdf , SIZE = 50, MAXSIZE = 500, FILEGROWTH = 25), FILEGROUP FG_DatosVentasDB ( NAME = FG_DatosVentasDB_Data, FILENAME = C:\Program Files\Microsoft SQL Server\MSSQL10.MSS QLSERVER\MSSQL\DATA\FG_DatosVentasDB .ndf , SIZE = 50, MAXSIZE = 500, FILEGROWTH = 25) LOG ON ( NAME = VentasDB_log, FILENAME = C:\Program Files\Microsoft SQL Server\MSSQL10.MSS QLSERVER\MSSQL\DATA\VentasDB.ldf , SIZE = 25, MAXSIZE = 250, FILEGROWTH = 12) /*Modificando el File Group por Defecto*/ ALTERDATABASEVentasDB MODIFY FILEGROUP FG_DatosVentasDBDEFAULT /*Usando la Base de Datos*/ USE VentasDB GO /*Creando las Tablas de Datos*/ /*Creando la Tabla Departamento*/ CreateTableTB_Departamento (CodDepaChar(3) Primary Key, NombreDepaVarchar(50) No tNull, Estado Integer) GO /*Creando la Tabla Provincia*/ CreateTableTB_Provincia(CodDepaChar(3) notnull,CodProvinciaChar(3) NotNull, NombreProvinciaVarchar(50) NotNull, Estado Integer) Alter TableTB_ProvinciaAddForeign Key (CodDepa) ReferencesTB_Departamento(CodDe pa) Alter Table TB_Provincia Add Primary Key (CodDepa, CodProvincia) GO /*Creando la Tabla Distrito*/ CreateTableTB_Distrito(CodDepaChar(3) notnull,CodProvinciaChar(3) NotNull,CodDis tritoChar(3) NotNull, NombreDistritoVarchar(50) NotNull, Estado Integer) Alter TableTB_DistritoAddForeign Key (CodDepa,CodProvincia) ReferencesTB_Provin cia(CodDepa,CodProvincia) Alter TableTB_DistritoAddPrimary Key (CodDepa,CodProvincia,CodDistrito) GO /*Creando la Tabla TipoPersona*/ CreateTableTB_TipoPersona(IdTipoPersonaIntegerPrimary Key, DescripcionVarchar(20 ) NotNull, Estado Integer) GO /*Creando la Tabla Cliente*/ CreateTableTB_Cliente(IdClienteChar(6) PrimaryKey,IdTipoPersonaIntegerNotNullRef

erencesTB_TipoPersona, Ap_PaternoVarchar(30) NotNull,Ap_MaternoVarchar(30) NotNull, Nombres Varchar(50) NotNull, NombreComercialVarchar(50), RazonSocialVarchar(100),DNI Varchar(8), RUC Varchar(11), DireccionLegalVarchar( 100) NotNull, CodDepaChar(3) NotNull, CodProvinciaChar(3) NotNull, CodDistritoChar(3) NotNull, DireccionAlternativaVar char(100), TelefonoInteger, Celular Smallint,FaxInteger, Sexo Char(1), EstadoCivilChar(1), FechaInscripcion Date, Estado Integer) Alter Table TB_Cliente Add Foreign Key (CodDepa, CodProvincia, CodDistrito) Refe rences TB_Distrito GO /*Crando la Tabla LineaProducto*/ Create Table TB_LineaProducto (IdLineaChar(8) Not Null Primary Key, DescripcionV archar(30) Not Null, Estado Integer) GO /*Creando la Tabla UnidadesMedida*/ CreateTableTB_UnidadesMedida (IdUnidadmedidaChar(3) Primary Key, DescripcionVarc har(20) NotNull, Estado Integer) GO /*Creando la Tabla Producto*/ CreateTableTB_Producto(IdProductoChar(8) Primary Key, IdLineaChar(8) referencesT B_LineaProducto, DescripcionLocalVarchar(50) NotNull, DescripcionInglesVarchar(50), IdUn idadMedidaChar(3) referencesTB_UnidadesMedida, NumeroSerieVarchar(20), NumeroLoteInteger, PrecioLocalActualFloat, PrecioDolarAc tualFloat, PrecioPromedioMensualFloat, StockActualInteger, StockMinimoInteger, StockMaximoInteger, Estado Integer) GO /*Creando la Tabla Estado*/ CreateTableTB_Estado(IdEstadoIntegerPrimary Key, DescripcionVarchar(20) NotNull, Estado Integer) GO /*Creando la Tabla Pedido*/ Create Table TB_Pedido(NumberPedido Integer Primary Key, IdCliente Char(6) Not N ull, FechaPedido Date Not Null, IdEstado Integer Not Null,foreign key (IdCliente) ref erences TB_Cliente, foreign key (IdEstado) references TB_Estado) GO /*Creando la Tabla DetallePedido*/ CreateTableTB_DetallePedido(NumberPedidoIntegerNotNullreferencesTB_Pedido,NroLin eaIntegerNotNull, IdProductoChar(8) NotNullreferencesTB_Producto, CantidadPedidaIntegerNotNull, Ca ntidadAtendidaInteger, CantidadFaltanteInteger) Alter Table TB_DetallePedido Add Primary Key (NumberPedido, NroLinea) GO /*Creando la Tabla Factura*/ CreateTableTB_Factura (NumeroFacturaIntegerPrimary Key, NumberPedidoIntegerNotNu llreferencesTB_Pedido, IdClienteChar(6) NotNullreferencesTB_Cliente, FechaFactura Date NotNull, FechaRe gistro Date NotNull, FechaPago Date, MonedaFacturaChar(1) NotNull, PorcentajeDescuentoFloat, TotalDes cuentoFloat, IGVPorcentajeFloatNotNull,TotalIGVFloatNotNull, Impresa Char(1), IdEstadoInteger NotNullreferencesTB_Estado) GO /*Creando la Tabla DetalleFactura*/

Create Table TB_DetalleFactura (NumeroFactura Integer Not Null references TB_Fac tura, NroLinea Integer Not Null, IdProducto Char(8) Not Null references TB_Producto, C antidad Integer Not Null, PrecioVenta Float Not Null, IGVValor Float Not Null, SubTotalLinea Float Not Nul l, primary key(NumeroFactura,NroLinea)) GO

También podría gustarte