0
i̇ki sorgu birleştirme
---
select * from products
where productid in
(select productid
from [order details]
where quantity>100)
---
i̇ngilizceyi türkçeye çevirme
select companyname, contactname,
'ulke' = case
when country='uk' then 'ingiltere'
when country='spain' then 'ispanya'
else country end
from customers
---
prosedur içinde değişkeni çalıştırmak
create proc sp_sorgu
as
declare @query nvarchar(500)
set @query='select * from customers'
exec (@query)
sp_sorgu 'customers'
---
i̇stediğimiz tabloyu getirme
alter proc sp_sorgu
@tabloadi nvarchar(50)
as
declare @query nvarchar(500)
set @query='select * from'+ @tabloadi
exec (@query)
sp_sorgu 'customers'
---
alter proc sp_sorgu
@id nvarchar(50)
as
declare @query nvarchar(500)
set @query='select * from products where productid='+@id
exec (@query)
sp_sorgu '1'
---
alter proc sp_sorgu
@id nvarchar(50)
as
declare @query nvarchar(500)
set @query='select * from products where productid in ('+@id+')'
exec (@query)
sp_sorgu '1,2,3,5,10,25
---
silmeme
alter trigger silinmesin
on customers
instead of delete
as
declare @id nvarchar(50)
set @id=(select customerid from deleted)
update customersset silindimi=1
where customerid=@id
delete from customers
where customerid='anton'
---
sayisal
declare @random int
declare @sayac int
set @sayac=1
delete from tbl_sayi
while @sayac<7
begin
set @random=cast(rand()*48+1 as int)
if not exists (select sayi randomfrom tbl_sayi where sayi=@)
begin
insert into tbl_sayi
(sayi)
values
(@random)
set @sayac=@sayac+1
end
e