select top 2 * from dbo.Customers
select top 2 * from orders
select top 2 * from [order details]
select top 2 * from dbo.Products
select top 2 * from dbo.Employees
create view SalesDetails
AS
–CustomersName — ProductName — Quantity
select E.FirstName +’ ‘+ E.LastName as ‘Full Name’
,C.ContactName , P.ProductName , OD.Quantity
from [Order Details] OD inner join Orders O
on OD.OrderID = O.OrderID
inner join Customers C
on O.CustomerID = C.CustomerID
inner join Employees E
on O.EmployeeID = E.EmployeeID
inner join Products P
on OD.ProductID = P.ProductID
select * from SalesDetails
sp_help SalesDetails
sp_helptext SalesDetails
sp_depends SalesDetails
select * from INFORMATION_SCHEMA.TABLES
where table_name = ‘SalesDetails’
select * from INFORMATION_SCHEMA.VIEWS
where table_name = ‘SalesDetails’
create view AmericanCustomers
AS
select * from customers
where country = ‘usa’
select * from AmericanCustomers
alter table customers
add MobilePhone varchar(15) null
select * from customers
sp_depends AmericanCustomers
create view OgretmenDers
as
select O.Adi + ‘ ‘ + O.Soyadi as ‘OgretmenAdi’
,D.DersAdi
from Ogretmenler O inner join Dersler D
on O.DersID = D.DersID
select * from OgretmenDers
sp_refreshview AmericanCustomers
sp_depends AmericanCustomers
select * from AmericanCustomers
create view UKCustomers
with encryption
as
select * from customers
where country = ‘uk’
select * from UKCustomers
sp_depends UKCustomers
sp_helptext UKCustomers
select * from INFORMATION_SCHEMA.VIEWS
where table_name = ‘UKCustomers’
select * from ogretmenler
select * from ogretmenders
drop view OgretmenDers
create view OgretmenDers
with schemabinding
as
select O.Adi + ‘ ‘ + O.Soyadi as ‘OgretmenAdi’
,D.DersAdi
from dbo.Ogretmenler O inner join dbo.Dersler D
on O.DersID = D.DersID
select * from OgretmenDers
delete from dersler
where dersid = 7
sp_helptext OgretmenDers
drop table ogretmenler
alter view OgretmenDers
as
select O.Adi + ‘ ‘ + O.Soyadi as ‘OgretmenAdi’
,D.DersAdi
from dbo.Ogretmenler O inner join dbo.Dersler D
on O.DersID = D.DersID
create view BrazilianCustomers
as
select * from customers
where country = ‘Brazil’
with check option
update BrazilianCustomers
set country = ‘Turkey’
where customerID = ‘FAMIA’
select top 2 * from employees
select top 2 * from dbo.EmployeeTerritories
select top 2 * from dbo.Territories
select top 2 * from region
Sql View Örnekleri
Hiç yorum yok:
Yorum Gönder