Consultas Basicas SQL Server
djalburbApuntes27 de Mayo de 2018
497 Palabras (2 Páginas)125 Visitas
create table City(
Id int identity(1,1) primary key,
NombreCity varchar(100)
)
insert into City(NombreCity) values ('Managua'), ('Sauce'), ('Leon'), ('Chinandega'), ('Sabana Grande'), ('San Martin'), ('San Antonio')
--select * from ciudad
create table persona(
Id int primary key,
Nombre nvarchar(100),
Apellido nvarchar(100),
Ciudad int foreign key references City(Id),
Edad int
)
insert into persona(Id, Nombre, Apellido, Ciudad, Edad) values (1, 'Scarleth', 'Quiroz', 2, 18)
insert into persona(Id, Nombre, Apellido, Ciudad, Edad) values (2, 'Tatiana', 'Toruño', 1, 20)
insert into persona(Id, Nombre, Apellido, Ciudad, Edad) values (3, 'Iliana', 'Bucardo', 2,19)
insert into persona(Id, Nombre, Apellido, Ciudad, Edad) values (4, 'Kenia', 'Idiaquez', 3, 17)
insert into persona(Id, Nombre, Apellido, Ciudad, Edad) values (5, 'Miriam', 'Jarquin', 4, 20)
insert into persona(Id, Nombre, Apellido, Ciudad, Edad) values (6, 'Kenya', 'Lopez', 1, 21)
insert into persona(Id, Nombre, Apellido, Ciudad, Edad) values (7, 'Lizareth', 'Icabalzeta', 5, 18)
insert into persona(Id, Nombre, Apellido, Ciudad, Edad) values (8, 'Eveling', 'Rivera', 6, 18)
insert into persona(Id, Nombre, Apellido, Ciudad, Edad) values (9, 'Keyling', 'Mejia', 7, 18)
--select * from persona where Id between 4 and 7
--select Nombre, Apellido from persona where Ciudad = 'Sauce'
--select Nombre from persona where Edad>=19 and Edad<=21
--select * from persona where Edad=18 or Edad =19
--select * from persona where Ciudad='Sauce' And(Edad=19 or Edad=18)
--select * from persona Where Ciudad In('Managua', 'Sauce')
--select * from persona Where Ciudad not in('Managua')
--select concat(Nombre,',', Edad) as Edad from persona
--select Nombre, Edad+30 from persona
--select UPPER(Nombre), Edad+30 from persona
--select Lower(Nombre), Edad+30 from persona
--select Nombre, SQRT(Edad) as RaizEdad from persona
--select AVG(Edad) as PromedioEdad from persona
--select SUM(Edad) as SumatoriaEdad from persona
--select Nombre, Edad from persona where Edad>(select avg(edad) from persona) Order by Edad Asc
--select * from persona where Nombre LIKE 'K%'
--select * from persona where Nombre Like '%A'
select persona.Nombre, City.NombreCity from persona inner join City on personas.Ciudad = City.Id
...