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 Varchar(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(100) 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 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(100)
)
As
Begin
Declare @retVal Int
Begin Try
if exists(select * from Urunler where Ad = @Ad)
Select @retVal = 0
else
begin
insert into Urunler Values(@Ad)
Select @retVal = 1
end
End Try
Begin Catch
Select @retVal = -1
End Catch
Return @retVal
End
Go
Create Proc SP_IlUrunleriEkle
(
@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üneydoğ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_IlUrunleriEkle 17,1,1,500000,@m output;
Exec SP_IlUrunleriEkle 35,2,2,250000,@m output;
Exec SP_IlUrunleriEkle 7,3,3,125000,@m output;
Exec SP_IlUrunleriEkle 42,4,4,354235,@m output;
Exec SP_IlUrunleriEkle 52,5,5,225000,@m output;
Exec SP_IlUrunleriEkle 25,6,6,154200,@m output;
Exec SP_IlUrunleriEkle 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 = I.PlakaKodu
Where B.BolgeNo = @BolgeNo

Return @Miktar
End
Go
Create Function FN_BolgeyeGoreUretim
(
@BolgeNo Int
)
Returns Table
As
Return Select
B.BolgeAdi,
I.Ad 'İl Adı',
U.Ad 'Ürün 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
Where B.BolgeNo = @BolgeNo
Go
Create Function FN_DonemeGoreUretim
(
@DonemNo Int
)
Returns Table
as
Return Select
B.BolgeAdi,
I.Ad 'İl Adı',
U.Ad 'Ürün 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
Where UD.DonemNo = @DonemNo
Go
Create Trigger TR_BolgeSilme
On Bolgeler
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_UrunDonemiSilme
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 =ToplamUretim+ @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.io is a web-based application for 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 12 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.