Page 164 - IT-802_class_12
P. 164

Following are the primary keys:
          (a) Dept_ID is the primary key of Department relation.

          (b) Teacher_ID is the primary key of Teacher relation.
        Now you may notice that Dept_ID, the primary key of relation in Department, is also present in the relation Teacher.
        The reason is that every teacher belongs to a particular department. Now that means Dept_ID of Teacher relation must
        have a value that exists in Dept_ID attribute of Department relation or it can be NULL in case a teacher has not yet
        been assigned to a department. We say that Dept_ID of Teacher relation is a foreign key that references primary key
        of Department relation (Dept_ID).

        It is important to emphasise that it is not necessary to have same name for the foreign key as of the corresponding
        referenced primary key. The above two schemas can also be written as follows:
          (a) Department (Dept_Name, Dept_ID, No_of_Teachers)
          (b) Teacher (Teacher_Name, Teacher_ID, Dept_No, Subject)

        Where Dept_No is the foreign key that references Dept_ID of Department relation.
        A foreign key may also refer to the same relation. For example, suppose we have to create a database of all residents
        in a colony along with their best neighbors. Consider the following relation:
        Residents (Name, RID, Block_no, House_no, Floor, Neighbor_RID)

        The Primary key of this relation is RID (Resident ID). In order to store information about neighbours we have created
        a foreign key Neighbor_RID that references RID of Residents. Note that the referencing and referenced relation are
        same in this case.
          1.4 stRuctuReD QueRy language (sQl)


        SQL is a high-level interactive language that allows users to specify what is required to be done in the form of queries.
        SQL stands for Structured Query Language. It is the standard language for managing relational databases and performing
        various operations on the data in the tables. It would enable us to store, retrieve, and manipulate data in the form of
        tables. It consists of two languages: Data Definition Language (DDL) and Data Manipulation Language (DML), where DDL
        is a language used to specify the restrictions and structure of data and DML is used to add, alter, and remove data from
        a database. Unlike other high-level languages, we do not need to specify how the SQL operations are implemented. The
        database software which uses SQL is MySQL. Let us read about this software.
        MySQL is one of the most popular database management system software used for managing the relational database. It
        is an open-source RDBMS software that is available free of cost. It can run on all operating systems, including Linux, Unix
        and Windows. It is popular for web-based applications and online publishing.
        To use MySQL on the computer, you need to install it.
        1.4.1 Installing MySQL

        MySQL is an open-source RDBMS software that can be easily downloaded from the official website. Perform the
        following steps to download and install MySQL:
         1   Visit the following link:

             https://dev.mysql.com/downloads
         2   Click on MySQL Installer for Windows.







          162   Touchpad Information Technology-XII
   159   160   161   162   163   164   165   166   167   168   169