0% found this document useful (0 votes)
28 views4 pages

Codigo en SQL: - Creación de Base de Datos

The document contains SQL code to create a database called "Reunion" with tables for registrants, payments, and accompanying companies. Data is inserted into the registrant table with names, surnames, and registration dates for 10 people. The code also creates foreign key constraints between the tables and shows examples of updating and deleting rows from a table.

Uploaded by

Carlos Tucto
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views4 pages

Codigo en SQL: - Creación de Base de Datos

The document contains SQL code to create a database called "Reunion" with tables for registrants, payments, and accompanying companies. Data is inserted into the registrant table with names, surnames, and registration dates for 10 people. The code also creates foreign key constraints between the tables and shows examples of updating and deleting rows from a table.

Uploaded by

Carlos Tucto
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Buenas tardes Ingeniero Ponce lo saluda Yessenia Valverde Meca primero disculparme por la

forma de presentar mi trabajo, no quiero excusarme pero no pude descargar el programa aunque
lo intente muchas veces, espero de comprension. Gracias.

CODIGO EN SQL
--Creación de Base de datos
USE master;
GO

CREATE DATABASE Reunion


ON PRIMARY
(
NAME = Reunion_dat,
FILENAME = 'C:\carpeta1\Reunion.mdf',
SIZE = 5MB,
MAXSIZE = 100MB,
FILEGROWTH = 1MB
)

LOG ON
(
NAME = Reunion _log,
FILENAME = 'C:\carpeta1\Reunion.ldf',
SIZE = 5,
MAXSIZE = unlimited,
FILEGROWTH = 1
);

GO

--Creacion de tablas
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [inscritos]
(
[Nombre] nvarchar (15)NOT NULL,
[ApellidoPat] nvarchar (15) NOT NULL,
[ApellidoMat] nvarchar (15) NOT NULL,
[FechaInscr] date NOT NULL,

CONSTRAINT [PK_ inscritos] PRIMARY KEY CLUSTERED


(
[FechaInscr] 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_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [pago]
(
[TipoPago] nvarchar (10)NOT NULL,
[compañia] nvarchar (2) NOT NULL,

CONSTRAINT [PK_ pago] PRIMARY KEY CLUSTERED


(
[TipoPago] 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_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [Compañia]
(
[Acompañante] nvarchar (2) NOT NULL,

CONSTRAINT [PK_ Compañia] PRIMARY KEY CLUSTERED


(
[Acompañante] 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

--Diagrama de Relaciones

/****** Object: ForeignKey [FK_pago_inscritos] ******/


ALTER TABLE [dbo].[ TipoPago] WITH CHECK ADD CONSTRAINT
[FK_Pago_ TipoPago] FOREIGN KEY([FechaInscr])
REFERENCES [dbo]. [inscritos] ([FechaInscr])

GO
ALTER TABLE [dbo].[pago]
CHECK CONSTRAINT [FK_pago_ inscritos]

GO

/****** Object: ForeignKey [FK_pago_inscritos] ******/


ALTER TABLE [dbo].[ Compañia] WITH CHECK ADD CONSTRAINT
[FK_ Acompañante _ Compañia] FOREIGN KEY([FechaInscr])
REFERENCES [dbo]. [Acompañante] ([FechaInscr])

GO
ALTER TABLE [dbo].[Compañia]
CHECK CONSTRAINT [FK_ Compañia_ inscritos]

GO

-- Ingresar datos a Las tablas--


--tabla: inscritos
INSERT INTO inscritos (Nombre, ApellidoPat, ApellidoMat, FechaInscr)
VALUES('Maria','Lopez','Acevedo','05/08/2017')
INSERT INTO inscritos (Nombre, ApellidoPat, ApellidoMat, FechaInscr)
VALUES('Lucas','Matinez','Posada', '08/09/2017')
INSERT INTO inscritos (Nombre, ApellidoPat, ApellidoMat, FechaInscr)
VALUES('Miguel','Gonzales','Falconi', '31/08/2017')
INSERT INTO inscritos (Nombre, ApellidoPat, ApellidoMat, FechaInscr)
VALUES('Lucia','Buitron','Negreiros', '01/10/2017')
INSERT INTO inscritos (Nombre, ApellidoPat, ApellidoMat, FechaInscr)
VALUES('Juan','Silva','Cruces', '15/11/2017')
INSERT INTO inscritos (Nombre, ApellidoPat, ApellidoMat, FechaInscr)
VALUES('Yoel','Soto','Medina', '20/09/2017')
INSERT INTO inscritos (Nombre, ApellidoPat, ApellidoMat, FechaInscr)
VALUES('Emilia','Borques','Zelada', '29/11/2017')
INSERT INTO inscritos (Nombre, ApellidoPat, ApellidoMat, FechaInscr)
VALUES('Erica','Jimenez','Casas', '02/08/2017')
INSERT INTO inscritos (Nombre, ApellidoPat, ApellidoMat, FechaInscr)
VALUES('Ana','Quiñonez','Mendez', '09/08/2017')
INSERT INTO inscritos (Nombre, ApellidoPat, ApellidoMat, FechaInscr)
VALUES('Katy','Perez','Arcos', '17/11/2017')
SELECT * FROM inscritos
-- MODIFICACIÓN DE DATOS DE UNA FILA DE UNA TABLA
--UPDATE NOMBRE DE LA TABLA xyz
--SET campo1 = 'nuevo valor del campo de la tabla xyz'
--WHERE campo2 = 'valor campo 2 de la tabla xyz'
--SELECT * FROM NOMBRE DE LA TABLA xyz

--ELIMINADO FILAS DE UNA TABLA


DELETE FROM inscritos
WHERE FechaInscr = '03/09/2017';
--Para eliminar o remover filas existentes en una tabla

--DELETE FROM nombreTabla


--WHERE campo2 = 'valorcampo2'

You might also like