Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

Unidad 2. Actividad 2.

Crear una base datos


Una base de datos relacional es un tipo de base de datos que almacena y proporciona
acceso a puntos de datos relacionados entre sí. Las bases de datos relacionales se
basan en el modelo relacional, una forma intuitiva y directa de representar datos en
tablas.

Actividad a realizar

Crear una base datos


Crear 4 tablas
Insertar no menos de 20 registros en cada tabla
Realizar 50 consultas a estas tablas
Actualizar 10 registros
Borrar 5 registros
Crear 2 vistas
Crear un procedimiento almacenado
Copiar todos scripts utilizados en el documento

-- Create a database
USE master;
GO
CREATE DATABASE DemoDB2
ON
( NAME = DemoDB2_dat,
FILENAME = 'C:\Data\DemoDB2.mdf',
SIZE = 100MB, MAXSIZE = 500MB,
FILEGROWTH = 20%
)
LOG ON
( NAME = DemoDB2_log,
FILENAME = 'C:\Logs\DemoDB2.ldf',
SIZE = 20MB,
MAXSIZE = UNLIMITED,
FILEGROWTH = 10MB
);
GO

-- View database info


EXEC sp_helpdb DemoDB2

USE master;
GO

USE AdventureWorks
GO
select * FROM HumanResources.Department
select * FROM HumanResources.Employee
select * FROM Sales.Store
select * FROM Person.Person
select 'FirstName' from Person.Person
select 'MiddleName' from Person.Person
select 'LastName' from Person.Person
select Firstname from Person.Person
select * FROM HumanResources.Department WHERE name='Pedro'
select * FROM HumanResources.Department WHERE Groupname='%R'
select * FROM HumanResources.Department WHERE Groupname='%R%'
select * FROM HumanResources.Department WHERE Groupname='R%'
select * FROM Person.Person Where FirstName='Ken' AND LastName='Sánchez'
select * FROM Person.Person WHERE LastName BETWEEN 'Duffy' AND 'Walters'
select * FROM Person.Person ORDER BY 'FirstName' DESC
select * FROM Person.Person ORDER BY 'LastName' DESC
select * FROM Person.Person ORDER BY 'MiddleName' DESC
INSERT INTO Person.Person VALUES ('Roberick','Pena')
INSERT INTO Person.Person VALUES ('Maria','Castillo')
INSERT INTO Person.Person (LastName) VALUES (Sayayin)
INSERT INTO Person.Person (FirstName) VALUES (Goku)
INSERT INTO HumanResources.Department (Name) VALUES (Yanikekero)
INSERT INTO HumanResources.Department(Name) VALUES (Portero)
INSERT INTO HumanResources.Department (Name) VALUES (Cocina)
INSERT INTO HumanResources.Employee (VacationHours) VALUES (98)
INSERT INTO HumanResources.Employee (JobTitle) VALUES (Barajista)
UPDATE Person.Person SET LastName='Sánchez'where LastName='Perez'
UPDATE Person.Person SET LastName='Erickson' where LastName='Goldberg'
UPDATE Person.Person SET LastName='Martinez' where LastName='White'
UPDATE Person.Person SET FirstName='Sam' where FirstName='Matt'
UPDATE HumanResources.Department SET Name='LimpiaBotas' where Name='Engeineering'
UPDATE HumanResources.Department SET GroupName='Vividor' where
GroupName='Research and Development'
UPDATE HumanResources.Employee SET MaritalStatus='Cogio' where MaritalStatus='M'
UPDATE HumanResources.Employee SET Gender='Chuki' where Gender='M'
UPDATE Sales.Store SET SalesPersonID='279' where SalesPersonID='278'
UPDATE Sales.Store SET SalesPersonID='277' where SalesPersonID='276'
DELETE FROM Person.Person Where LastName='Perez'
DELETE FROM Person.Person Where MiddleName='Daniel'
DELETE FROM Person.Person Where FirstName='Luis'
DELETE FROM HumanResources.Department Where Name='Marketing'
DELETE FROM Sales.Store Where Name='Riders Company'
DELETE FROM Sales.Store Where Name='The Bike Mechanics'
DELETE FROM HumanResources.Employee Where NationalIDNumber='295847284'
DELETE FROM HumanResources.Employee Where NationalIDNumber='245797967'
SELECT COUNT(*) FROM HumanResources.Department
SELECT COUNT(*) FROM HumanResources.Employee
SELECT COUNT(*) FROM Sales.Store
SELECT COUNT(*) FROM Person.Person
CREATE VIEW HumanResources.EmployeeHireDate
AS
SELECT p.FirstName, p.LastName, e.HireDate
FROM HumanResources.Employee AS e JOIN Person.Person AS p
ON e.BusinessEntityID = p.BusinessEntityID ;
GO

CREATE VIEW [HumanResources].[vEmployee]


AS
SELECT
e.[BusinessEntityID]
,p.[Title]
,p.[FirstName]
,p.[MiddleName]
,p.[LastName]
,p.[Suffix]
,e.[JobTitle]
,pp.[PhoneNumber]
,pnt.[Name] AS [PhoneNumberType]
,ea.[EmailAddress]
,p.[EmailPromotion]
,a.[AddressLine1]
,a.[AddressLine2]
,a.[City]
,sp.[Name] AS [StateProvinceName]
,a.[PostalCode]
,cr.[Name] AS [CountryRegionName]
,p.[AdditionalContactInfo]
FROM [HumanResources].[Employee] e
INNER JOIN [Person].[Person] p
ON p.[BusinessEntityID] = e.[BusinessEntityID]
INNER JOIN [Person].[BusinessEntityAddress] bea
ON bea.[BusinessEntityID] = e.[BusinessEntityID]
INNER JOIN [Person].[Address] a
ON a.[AddressID] = bea.[AddressID]
INNER JOIN [Person].[StateProvince] sp
ON sp.[StateProvinceID] = a.[StateProvinceID]
INNER JOIN [Person].[CountryRegion] cr
ON cr.[CountryRegionCode] = sp.[CountryRegionCode]
LEFT OUTER JOIN [Person].[PersonPhone] pp
ON pp.BusinessEntityID = p.[BusinessEntityID]
LEFT OUTER JOIN [Person].[PhoneNumberType] pnt
ON pp.[PhoneNumberTypeID] = pnt.[PhoneNumberTypeID]
LEFT OUTER JOIN [Person].[EmailAddress] ea
ON p.[BusinessEntityID] = ea.[BusinessEntityID];

GO

EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Employee names


and addresses.' , @level0type=N'SCHEMA',@level0name=N'HumanResources',
@level1type=N'VIEW',@level1name=N'vEmployee'
GO
Procedimiento almacenado

Create procedure saludar


as
print 'Hola, como estas'
go

execute saludar

Roberick Peña A00142090

You might also like