NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

/*Create database TarimUretim
Go
Use TarimUretim */
go
create Table Bolgeler
(
BolgeNo int identity primary key,
BolgeAdi nvarchar(100) Unique,
Aktif bit default 1

)
Go
Create Table Iller
(
PlakaKodu int Primary key,
BolgeNo int,
Ad Varchar(50) unique,
TelefonKodu varchar(5) unique,
Aktif bit default 1

Constraint FK_Iller_BolgeNo foreign key (BolgeNo) references Bolgeler(BolgeNo)

)

Go
Create Table Urunler
(
UrunNo int identity primary key,
Ad varchar(50) unique
)

Go
Create Table UrunDonemleri
(
DonemNo int identity primary key,
DonemTanimi varchar(50) unique,
Aktif bit default 1
)
Go
Create Table IlUrunleri
(
PlakaKodu int,
DonemNo int,
UrunNo int,
Miktar int,
Constraint FK_IlUrunleri_PlakaKodu Foreign key (PlakaKodu) References Iller(PlakaKodu),
Constraint FK_IlUrunleri_DonemNo Foreign key (DonemNo) References UrunDonemleri(DonemNo),
Constraint FK_IlUrunleri_UrunNo Foreign key (UrunNo) References Urunler(UrunNo)
)
Go
Create Proc SP_BolgeEkle
(
@BolgeAdi varchar(100),
@Aktif bit
)
As
Begin
Insert Into Bolgeler(BolgeAdi,Aktif) Values(@BolgeAdi, @Aktif)
End

Go
Create Proc SP_IlEkle
(
@PlakaKodu int,
@BolgeNo int,

@Ad Varchar(50),
@TelefonKodu varchar(5),
@Aktif bit,
@SatirSayisi int Output
)
As
Begin
Insert Into Iller Values (@PlakaKodu,@BolgeNo,@Ad,@TelefonKodu,@Aktif)
Select @SatirSayisi = @@ROWCOUNT
End

Go
Create Proc Sp_DonemEkle
(
@DonemTanimi Varchar(50),
@Aktif bit
)
AS
Begin
Declare @rValue int
Begin Try
Insert Into UrunDonemleri
Values (@DonemTanimi, @Aktif)
Select @rValue =@@ROWCOUNT
End Try
Begin catch
Select @rValue=ERROR_NUMBER()

End catch
Return @rValue
End

Go
Create Proc SP_UrunEkle
(
@Ad varchar(50)
)
AS
Begin Try
Declare @retVal int
if exists (Select * From Urunler Where Ad=@Ad)
Select @retVal=0
else
Select @retVal =1
end Try
Begin Catch
Select @retVal=-1
End Catch
Return @retVal

Go

-- soru 7
Create Proc SP_IlUrunleri
(
@PlakaKodu int,
@DonemNo int,
@UrunNo int,
@Miktar int,
@Mesaj Varchar(150) output
)
As
Begin
Begin Try
Insert Into IlUrunleri Values (@PlakaKodu,@DonemNo,@UrunNo,@Miktar)
Set @Mesaj='Kayıt Başarılı'
End Try
Begin Catch
Set @Mesaj='Eklemeye Çalıştığınız Verilerden Biri ya da Bir Kaçı Tanımlı Değil!'

End Catch
End
Go
Exec SP_BolgeEkle 'Marmara Bölgesi',1;
Go
Exec SP_BolgeEkle 'Ege Bölgesi',1;
Go
Exec SP_BolgeEkle 'Akdeniz Bölgesi',1;
Go

Exec SP_BolgeEkle 'İç Anadolu Bölgesi',1;
Go
Exec SP_BolgeEkle 'Karadeniz Bölgesi',1;
Go
Exec SP_BolgeEkle 'Doğu Anadolu Bölgesi',1;
Go
Exec SP_BolgeEkle 'Güney Doğu Anadolu Bölgesi',1;
Go
Declare @ss int
Exec SP_IlEkle 17,1,'Çanakkale','286',1, @ss output;
Exec SP_IlEkle 35,2,'İzmir','232',1, @ss output;
Exec SP_IlEkle 7,3, 'Antalya','242',1, @ss output;
Exec SP_IlEkle 42,4,'Konya','332',1, @ss output;
Exec SP_IlEkle 52,5,'Ordu','452',1, @ss output;
Exec SP_IlEkle 25,6,'Erzurum','442',1, @ss output;
Exec SP_IlEkle 63,7,'Şanlıurfa','414',1, @ss output;
Go
Exec Sp_DonemEkle '2010 yılı',1;
Go
Exec Sp_DonemEkle '2011 yılı',1;
Go
Exec Sp_DonemEkle '2012 yılı',1;
Go
Exec Sp_DonemEkle '2013 yılı',1;
Go
Exec Sp_DonemEkle '2014 yılı',1;
Go
Exec Sp_DonemEkle '2015 yılı',1;
Go
Exec Sp_DonemEkle '2016 yılı',1;
Go
Exec SP_UrunEkle 'Domates'
Go
Exec SP_UrunEkle 'İncir'
Go
Exec SP_UrunEkle 'Portakal'
Go
Exec SP_UrunEkle 'Buğday'
Go
Exec SP_UrunEkle 'Fındık'
Go
Exec SP_UrunEkle 'Arpa'
Go
Exec SP_UrunEkle 'Mercimek'
Go
Declare @m varchar(150)
Exec SP_IlUrunleri 17,1,1,50000, @m output;
Exec SP_IlUrunleri 35,2,2,25000, @m output;
Exec SP_IlUrunleri 7,3,3,12500, @m output;
Exec SP_IlUrunleri 42,4,4,354235, @m output;
Exec SP_IlUrunleri 52,5,5,225000, @m output;
Exec SP_IlUrunleri 25,6,6,154200, @m output;
Exec SP_IlUrunleri 63,7,7,25000, @m output;

Go
Create View VW_OzetTablo
AS
Select
B.BolgeAdi,
I.Ad 'IlAdi',
U.Ad,
Ud.DonemTanimi,
IU.Miktar

From Bolgeler B
Join Iller I On I.BolgeNo=B.BolgeNo
Join IlUrunleri IU on IU.PlakaKodu= I.PlakaKodu
Join Urunler U on U.UrunNo=IU.UrunNo
Join UrunDonemleri UD on Ud.DonemNo= IU.DonemNo

Go
Create Function FN_BolgeUretimHesapla
(
@BolgeNo int
)
Returns int
As
Begin
Declare @Miktar int
Select
@Miktar= SUM(IU.Miktar)

From Bolgeler B
Join Iller I on I.BolgeNo=B.BolgeNo
Join IlUrunleri IU on Iu.PlakaKodu=ı.PlakaKodu
Where B.BolgeAdi=@BolgeNo
Return @Miktar
End

Go
Create Function FN_BolgeyeGoreUretim
(
@BolgeNo int
)
Returns Table
AS
Return Select
B.BolgeAdi,
I.Ad 'IlAdi',
U.ad 'ÜrünAdi',
Ud.DonemTanimi,
IU.Miktar
From Bolgeler B
Join Iller I on I.BolgeNo=B.BolgeNo
Join IlUrunleri IU On IU.PlakaKodu = I.PlakaKodu
Join Urunler U on U.UrunNo=IU.UrunNo
JOin UrunDonemleri Ud on Ud.DonemNo=IU.DonemNo
Where B.BolgeNo=@BolgeNo

Go
Create Function FN_DOnemeGoreUretim
(
@DonemNo int
)
Returns Table
As
return Select
B.BolgeAdi,
I.Ad 'IlAdi',
U.ad 'ÜrünAdi',
Ud.DonemTanimi,
IU.Miktar
From Bolgeler B
Join Iller I on I.BolgeNo=B.BolgeNo
Join IlUrunleri IU On IU.PlakaKodu = I.PlakaKodu
Join Urunler U on U.UrunNo=IU.UrunNo
JOin UrunDonemleri Ud on Ud.DonemNo=IU.DonemNo
Where Ud.DonemNo=@DonemNo

Go
Create Trigger TR_BolgeSilme on Bolgeler --dml trigger
Instead Of delete
AS
Declare @BolgeNo int
Select @BolgeNo = BolgeNo From deleted
Update Bolgeler Set Aktif=0 Where BolgeNo=@BolgeNo

Go
Create Trigger TR_IlSilme on Iller
Instead Of delete
AS
Declare @PlakaNo int
Select @PlakaNo = PlakaKodu From deleted
Update Iller Set Aktif=0 Where PlakaKodu=@PlakaNo

Go
Create Trigger TR_UrunDonemleriSilme on UrunDonemleri
Instead Of delete
AS
Declare @DonemNo int
Select @DonemNo = DonemNo From deleted
Update UrunDonemleri Set Aktif=0 Where DonemNo=@DonemNo

Go
Create Table DonemUretim
(
DonemId int ,
ToplamUretim int
)

Go
Create Trigger TR_UrunEklendi On IlUrunleri
For insert
AS
Declare @donemNo int
Declare @toplamMiktar int
Declare @Miktar int
Select @donemNo= DonemNo, @Miktar=Miktar From inserted
if Exists (Select * From IlUrunleri Where DonemNo=@donemNo)

Begin

Update DonemUretim
Set ToplamUretim=@toplamMiktar+@Miktar
Where DonemId=@donemNo
End
Else
Begin
Select @toplamMiktar=SUM(Miktar)
From IlUrunleri
Where DonemNo=@donemNo
Insert Into DonemUretim Values (@donemNo, @toplamMiktar)
End


     
 
what is notes.io
 

Notes is a web-based application for online taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000+ notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 14 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.