An entity is an object in the real world that is distinguishable from other objects. Examples include the following: the Green Dragonzord toy, the toy department, the manager of the toy department, the home address of the manager of the toy department. It is often useful to identify a collection of similar entities. Such a collection is called an entity set. Note that entity sets need not be disjoint; the collection of toy department employees and the collection of appliance department employees may both contain employee John Doe (who happens to work in both departments). We could also define an entity set called Employees that contains both the toy and appliance department employee sets.
An entity is described using a set of attributes. All entities in a given entity set have the same attributes; this is what we mean by similar. (This statement is an oversimplification, as we will see when we discuss inheritance hierarchies in Section 2.4.4, but it suffices for now and highlights the main idea.) Our choice of attributes reflects the level of detail at which we wish to represent information about entities. For example, the Employees entity set could use name, social security number (ssn), and parking lot (lot) as attributes. In this case we will store the name, social security number, and lot number for each employee. However, we will not store, say, an employee's address (or gender or age).
For each attribute associated with an entity set, we must identify a domain of possible values. For example, the domain associated with the attribute name of Employees might be the set of 20-character strings.1 As another example, if the company rates employees on a scale of 1 to 10 and stores ratings in a field called mting, the associated domain consists of integers 1 through 10. Further, for each entity set, we choose a key. A key is a minimal set of attributes whose values uniquely identify an entity in the set. There could be more than one candidate key; if so, we designate one of them as the primary key. For now we assume that each entity set contains at least one set of attributes that uniquely identifies an entity in the entity set; that is, the set of attributes contains a key. We revisit this point in Section 2.4.3.
The Employees entity set with attributes ssn, name, and lot is shown in Figure 2.1. An entity set is represented by a rectangle, and an attribute is represented by an oval. Each attribute in the primary key is underlined. The domain information could be listed along with the attribute name, but we omit this to keep the figures compact. The key is s.m.
Varlıklar, özellikler ve varlık kümeleri
Bir varlık, gerçek dünyada diğer nesnelerden ayırt edilebilen bir nesnedir. Örnekler arasında şunlar sayılabilir: Yeşil Dragonzord oyuncağı, oyuncak bölümü, oyuncak departmanının yöneticisi, oyuncak departmanının yöneticisinin ev adresi. Benzer varlıklar koleksiyonunu tanımlamak genellikle yararlıdır. Böyle bir koleksiyon bir varlık kümesi olarak adlandırılır. Varlık kümelerinin ayrılmaya ihtiyaç duymadığını unutmayın; oyuncak departmanı çalışanları topluluğu ve cihaz departmanı çalışanları topluluğunun her ikisi de çalışan John Doe'yu (her iki bölümde de görev yapan) içerebilir. Ayrıca, hem oyuncak hem de cihaz bölümü çalışan kümelerini içeren Çalışanlar adı verilen bir varlık grubu tanımlayabiliriz.
Bir varlık, bir dizi özellik kullanılarak tanımlanır. Belirli bir varlık kümesindeki tüm varlıklar aynı özelliklere sahiptir; benzer demekle kastettiğimiz budur. (Bu ifade, Bölüm 2.4.4'teki miras hiyerarşilerini ele aldığımızda göreceğimiz gibi, bir aşırı basitleştirmedir, ancak şu an için yeterlidir ve ana fikri vurgular.) Seçtiğimiz özellikler, varlıklar hakkındaki bilgiyi temsil etmek istediğimiz ayrıntı düzeyini yansıtır. Örneğin, çalışanlar kümesi, ad, sosyal güvenlik numarası (ssn) ve otopark hissesi (lot) özellik olarak kullanabilir. Bu durumda, her çalışan için adı, sosyal güvenlik numarası ve park yeri numarasını kayıtedeceğiz. Ancak, çalışanın adresini (veya cinsiyetini veya yaşını) saklamayız.
Bir varlık kümesi ile ilişkilendirilmiş her bir özellik için, olası değerlerin bir domain(etki alanı) ini tanımlamalıyız. Örneğin, Çalışanların adı özelliği ile ilişkilendirilen etki alanı, 20 karakterlik string olabilir. Başka bir örnek olarak, şirket çalışanlarını 1 ile 10 arasında bir ölçekte derecelendirir ve mting olarak adlandırılan bir alanda derecelendirmeleri saklarsa, ilgili etki alanı (domain) 1'den 10'a kadar olan tam sayılardan oluşur. Dahası, her varlık kümesi için bir anahtar seçeriz. Bir anahtar, değerleri kümedeki bir varlığı benzersiz olarak tanımlayan minimum özellik kümesidir. Birden fazla aday anahtarı olabilir; eğer öyleyse, bunlardan birini birincil anahtar olarak belirleriz. Şimdilik, her varlık kümesinin, varlık kümesindeki bir varlığı benzersiz olarak tanımlayan en az bir özellik kümesi içerdiğini varsayalım; Yani, özellikler kümesi bir anahtar içerir. Bu noktayı Bölüm 2.4.3'te yeniden ele alacağız.
Özellikler ssn, isim ve lot ile belirlenen çalışanlar, Şekil 2.1'de gösterilmiştir. Varlık kümesi bir dikdörtgenle temsil edilir ve bir özellik bir elips ile temsil edilir. Birincil anahtardaki her bir özelliğin altı çizilir. Etki alanı bilgisi, özellik adıyla birlikte listelenebilir, ancak bu rakamları kompakt tutmak için bunu çıkarırız. Anahtar s.m. dir