View Nedir?

Belirli bir sorgunun çalıştırılmasından türetilen sanal veya mantıksal tablo anlamındadır. Standart tablolara göre bazı avantajları vardır. Kısaca bunlar

  • Birden fazla tabloyu içeren bir sorgu view sayesinde sanal olarak tek bir tablo haline getirilebilir.
  • Bütünleştirilmiş tablo veya bütünleştirilmiş veri veya hesaplanıp sunulmuş veri olarak davranabilir.
  • Kompleks veriyi daha kolay görünür hale getirebilir.

CREATE TABLE IF NOT EXISTS `tblSections` (
  `Id` int(10) NOT NULL auto_increment,
  `Name` text NOT NULL,
  `Duration` tinyint(2) NOT NULL default '0',
  PRIMARY KEY  (`Id`)
) ENGINE=InnoDB  ;

CREATE TABLE IF NOT EXISTS `tblTeacherList` (
  `Id` int(10) NOT NULL auto_increment,
  `BolumId` int(10) NOT NULL default '0',
  `OgretmenId` int(10) NOT NULL default '0',
  PRIMARY KEY  (`Id`)
) ENGINE=InnoDB  ;

CREATE TABLE IF NOT EXISTS `tblTeachers` (
  `Id` int(10) NOT NULL auto_increment,
  `Ad` text NOT NULL,
  `Soyad` text NOT NULL,
  `Aciklama` text NOT NULL,
  PRIMARY KEY  (`Id`)
) ENGINE=InnoDB ;


İlk view'imiz aşağıdaki gibi olsun.
Create view Deneme As 
select 
	tblTeachers.Id AS OgretmentblId,
	tblTeachers.Ad AS Name tblTeachers.Soyad AS Surname,
	tblSections.Id AS SectionId,
	tblSections.Name AS SectionName 

from tblTeachers 
join tblSections 
join tblTeacherList 

where 
	((tblTeacherList.OgretmenId = tblTeachers.Id) and 
	(tblTeacherList.BolumId = tblSections.Id))
Artık ilk view'imiz hazır. Çalıştırmak için


mysql> select * from Deneme;
+---------------+-------+----------+-----------+-------------+
| OgretmentblId | Name  | Surname  | SectionId | SectionName |
+---------------+-------+----------+-----------+-------------+
|             6 | Burak | Telgeren |         3 | Kimya       | 
+---------------+-------+----------+-----------+-------------+
1 row in set (0.00 sec)


Öğretmen adını, hangi bölümde ders verdiğini basit bir sorgu ile görebilir hale geldik. İşte hepsi bu icon_razz

Trackbacks

The trackback uri for this entry is
http://www.ahmetyazici.org/blog//trackback.php/3/3

Listed below are the weblogs that reference this post





Comments



 
Name

Email

URL


Remember me?

Comments


Verification code
Verification code