Monday, January 10, 2022

Key & Types of Keys in Relational Model

 

What are Keys in DBMS?

KEYS in DBMS is an attribute or set of attributes which helps you to identify a row(tuple) in a relation(table). They allow you to find the relation between two tables. Keys help you uniquely identify a row in a table by a combination of one or more columns in that table. Key is also helpful for finding unique record or row from the table. Database key is also helpful for finding unique record or row from the table.

Example:

Employee IDFirstNameLastName
11AndrewJohnson
22TomWood
33AlexHale

In the above-given example, employee ID is a primary key because it uniquely identifies an employee record. In this table, no other employee can have the same employee ID.

In this tutorial, you will learn:

Why we need a Key?

Here are some reasons for using sql key in the DBMS system.

  • Keys help you to identify any row of data in a table. In a real-world application, a table could contain thousands of records. Moreover, the records could be duplicated. Keys in RDBMS ensure that you can uniquely identify a table record despite these challenges.
  • Allows you to establish a relationship between and identify the relation between tables
  • Help you to enforce identity and integrity in the relationship.

Types of Keys in DBMS (Database Management System)

There are mainly Eight different types of Keys in DBMS and each key has it’s different functionality:

  1. Super Key
  2. Primary Key
  3. Candidate Key
  4. Alternate Key
  5. Foreign Key
  6. Compound Key
  7. Composite Key
  8. Surrogate Key

Let’s look at each of the keys in DBMS with example:

  • Super Key – A super key is a group of single or multiple keys which identifies rows in a table.
  • Primary Key – is a column or group of columns in a table that uniquely identify every row in that table.
  • Candidate Key – is a set of attributes that uniquely identify tuples in a table. Candidate Key is a super key with no repeated attributes.
  • Alternate Key – is a column or group of columns in a table that uniquely identify every row in that table.
  • Foreign Key – is a column that creates a relationship between two tables. The purpose of Foreign keys is to maintain data integrity and allow navigation between two different instances of an entity.
  • Compound Key – has two or more attributes that allow you to uniquely recognize a specific record. It is possible that each column may not be unique by itself within the database.
  • Composite Key – is a combination of two or more columns that uniquely identify rows in a table. The combination of columns guarantees uniqueness, though individual uniqueness is not guaranteed.
  • Surrogate Key – An artificial key which aims to uniquely identify each record is called a surrogate key. These kind of key are unique because they are created when you don’t have any natural primary key.
  • What is the Super key?

    A superkey is a group of single or multiple keys which identifies rows in a table. A Super key may have additional attributes that are not needed for unique identification.

    Example:

    EmpSSNEmpNumEmpname
    9812345098AB05Shown
    9876512345AB06Roslyn
    199937890AB07James

    In the above-given example, EmpSSN and EmpNum name are superkeys.

    What is a Primary Key?

    PRIMARY KEY in DBMS is a column or group of columns in a table that uniquely identify every row in that table. The Primary Key can’t be a duplicate meaning the same value can’t appear more than once in the table. A table cannot have more than one primary key.

    Rules for defining Primary key:

    • Two rows can’t have the same primary key value
    • It must for every row to have a primary key value.
    • The primary key field cannot be null.
    • The value in a primary key column can never be modified or updated if any foreign key refers to that primary key.

    Example:

    In the following example, <code>StudID</code> is a Primary Key.

    StudIDRoll NoFirst NameLastNameEmail
    111TomPriceabc@gmail.com
    212NickWrightxyz@gmail.com
    313DanaNatanmno@yahoo.com

    What is the Alternate key?

    ALTERNATE KEYS is a column or group of columns in a table that uniquely identify every row in that table. A table can have multiple choices for a primary key but only one can be set as the primary key. All the keys which are not primary key are called an Alternate Key.

    Example:

    In this table, StudID, Roll No, Email are qualified to become a primary key. But since StudID is the primary key, Roll No, Email becomes the alternative key.

    StudIDRoll NoFirst NameLastNameEmail
    111TomPriceabc@gmail.com
    212NickWrightxyz@gmail.com
    313DanaNatanmno@yahoo.com

    What is a Candidate Key?

    CANDIDATE KEY in SQL is a set of attributes that uniquely identify tuples in a table. Candidate Key is a super key with no repeated attributes. The Primary key should be selected from the candidate keys. Every table must have at least a single candidate key. A table can have multiple candidate keys but only a single primary key.

    Properties of Candidate key:

    • It must contain unique values
    • Candidate key in SQL may have multiple attributes
    • Must not contain null values
    • It should contain minimum fields to ensure uniqueness
    • Uniquely identify each record in a table

    Candidate key Example: In the given table Stud ID, Roll No, and email are candidate keys which help us to uniquely identify the student record in the table.

    StudIDRoll NoFirst NameLastNameEmail
    111TomPriceabc@gmail.com
    212NickWrightxyz@gmail.com
    313DanaNatanmno@yahoo.com

    Candidate Key in DBMS

    Candidate Key in DBMS

    What is the Foreign key?

    FOREIGN KEY is a column that creates a relationship between two tables. The purpose of Foreign keys is to maintain data integrity and allow navigation between two different instances of an entity. It acts as a cross-reference between two tables as it references the primary key of another table.

    Example:

    DeptCodeDeptName
    001Science
    002English
    005Computer
    Teacher IDFnameLname
    B002DavidWarner
    B017SaraJoseph
    B009MikeBrunton

    In this key in dbms example, we have two table, teach and department in a school. However, there is no way to see which search work in which department.

    In this table, adding the foreign key in Deptcode to the Teacher name, we can create a relationship between the two tables.

    Teacher IDDeptCodeFnameLname
    B002002DavidWarner
    B017002SaraJoseph
    B009001MikeBrunton

    This concept is also known as Referential Integrity.

  • What is the Compound key?

    COMPOUND KEY has two or more attributes that allow you to uniquely recognize a specific record. It is possible that each column may not be unique by itself within the database. However, when combined with the other column or columns the combination of composite keys become unique. The purpose of the compound key in database is to uniquely identify each record in the table.

    Example:

    OrderNoPorductIDProduct NameQuantity
    B005JAP102459Mouse5
    B005DKT321573USB10
    B005OMG446789LCD Monitor20
    B004DKT321573USB15
    B002OMG446789Laser Printer3

    In this example, OrderNo and ProductID can’t be a primary key as it does not uniquely identify a record. However, a compound key of Order ID and Product ID could be used as it uniquely identified each record.

    What is the Composite key?

    COMPOSITE KEY is a combination of two or more columns that uniquely identify rows in a table. The combination of columns guarantees uniqueness, though individually uniqueness is not guaranteed. Hence, they are combined to uniquely identify records in a table.

    The difference between compound and the composite key is that any part of the compound key can be a foreign key, but the composite key may or maybe not a part of the foreign key.

    What is a Surrogate key?

    SURROGATE KEYS is An artificial key which aims to uniquely identify each record is called a surrogate key. This kind of partial key in dbms is unique because it is created when you don’t have any natural primary key. They do not lend any meaning to the data in the table. Surrogate key in DBMS is usually an integer. A surrogate key is a value generated right before the record is inserted into a table.

    FnameLastnameStart TimeEnd Time
    AnneSmith09:0018:00
    JackFrancis08:0017:00
    AnnaMcLean11:0020:00
    ShownWillam14:0023:00

    Above, given example, shown shift timings of the different employee. In this example, a surrogate key is needed to uniquely identify each employee.

    Surrogate keys in sql are allowed when

    • No property has the parameter of the primary key.
    • In the table when the primary key is too big or complicated.

    Difference Between Primary key & Foreign key

    Following is the main difference between primary key and foreign key:

    Primary KeyForeign Key
    Helps you to uniquely identify a record in the table.It is a field in the table that is the primary key of another table.
    Primary Key never accept null values.A foreign key may accept multiple null values.
    Primary key is a clustered index and data in the DBMS table are physically organized in the sequence of the clustered index.A foreign key cannot automatically create an index, clustered or non-clustered. However, you can manually create an index on the foreign key.
    You can have the single Primary key in a table.You can have multiple foreign keys in a table.

    Summary

    • What is key in DBMS: A key in DBMS is an attribute or set of attributes which helps you to identify a row(tuple) in a relation(table)
    • Keys in RDBMS allow you to establish a relationship between and identify the relation between tables
    • Eight types of key in DBMS are Super, Primary, Candidate, Alternate, Foreign, Compound, Composite, and Surrogate Key.
    • A super key is a group of single or multiple keys which identifies rows in a table.
    • A column or group of columns in a table which helps us to uniquely identifies every row in that table is called a primary key
    • All the different keys in DBMS which are not primary key are called an alternate key
    • A super key with no repeated attribute is called candidate key
    • A compound key is a key which has many fields which allow you to uniquely recognize a specific record
    • A key which has multiple attributes to uniquely identify rows in a table is called a composite key
    • An artificial key which aims to uniquely identify each record is called a surrogate key
    • Primary Key never accept null values while a foreign key may accept multiple null values.

Monday, January 3, 2022

How to Download Turbo C++ for Windows 7, 8 and 10 (32/64 bit)

Download

In this article, I’ll show you how to download Turbo C for Windows (or Turbo C++),  install Turbo C compiler on any version of Windows Operating System and write a C Program in Turbo C.

Turbo C and Turbo C++ are compilers for C and C++ (C plus plus) Programming Languages. They were originally developed by Borland Software Corporation as a combination of Integrated Development Environment (IDE) and Compiler.

Turbo C++ replaced Turbo C in the year 1990 and later both were discontinued. Turbo C/C++ was famous for its small size, speed of compilation, price, documentation and the whole integrated development environment.

The original Turbo C/C++ were 16 – bit compilers as they were developed for 16 – bit CPUs (Intel’s 8086 Series of Microprocessors).

Even though Turbo C is discontinued and is not compatible with the current generation systems (like Windows 7, 8 and 10), many programmers and developers still prefer to use the old Turbo C environment.

Personally, I started my C Programming training and development through Turbo C Compiler. So, in this post, I’ll take you through the process of how to download Turbo C, how to install Turbo C on any of the latest Windows Operating System i.e., Windows 7, Windows 8 and Windows 10, be it a 32 – bit version or a 64 – bit version.

What is a Compiler?

Before going in to Turbo C Compiler, we will first see what a Compiler is. A Compiler is a program or a software that transforms programs written in High Level Programming Languages such as C, C++, Python, etc. to Low Level Programming Languages like Assembly Language, Machine Code etc.

Turbo C is a C Programming Language Compiler that transforms programs written in C to Assembly or Machine Code to create an executable Program.

What makes Turbo C/C++ Special?

The original developers of Turbo C, Borland sold the Turbo C++ compiler to a company called Embarcadero Technologies. The Turbo C++ Compiler was later upgraded to their flagship Compiler called C++ Builder.

There are many Compilers for C and C++ Programming Languages but what makes Turbo C/C++ special is its speed of Compilation of the Programs, size of the overall software (Turbo C occupies very little memory), compatibility with wide range of I/O Modules, support for large projects, etc.

Hence, many programmers and software developers still prefer the old Turbo C Compiler and IDE to keep that nostalgic feel going on.

Download Turbo C for Windows (Turbo C++)

If Turbo C/C++ is discontinued, then how can we install it in our system? Even though Turbo C++ is discontinued, there are many simulators that work in a similar way to the original Turbo C and Turbo C++ and present that retro look with its iconic blue screen.

DOSBox is one such software that emulates a DOS Operating System. Using DOSBox, we can run x86 compatible games and software on our latest systems.

Using DOSBox, developers achieved to bring back the Turbo C++ Compiler to the latest version of Windows as the original Turbo C/C++ is a 16 – bit compiler.

Now, in order to install Turbo C++ on your computer (any 32 – bit or 64 – bit computer running on any Windows version from Windows 7), there are two ways you can proceed.

One way is to download the DOSBox Emulator and Turbo C++ Compiler separately and install them both on your computer. The other way is to simply download and install the Turbo C++ for Windows Application.

To download the Turbo C++ for Windows, follow this link.

How to Install Turbo C for Windows?

After downloading the application (it will be downloaded in a zip file), extract the zip file and double click on the setup.exe file (or on the Turbo C++ 3.2.msi file). The installation wizard will open. Click on next.

Turbo C for Windows Image 1

The license screen appears, accept the license terms and click on next.

Download Turbo C for Windows Image 7

One disadvantage of this Turbo C Installation on Windows is that you cannot modify the installation directory. The default location is “C:\TURBOC3\”.

Download Turbo C for Windows Image 8

Continue with the installation by clicking ‘Install’. After installation is complete, you will get a launch the application checkbox. Keep it checked and click on finish.

Download Turbo C for Windows Image 9

A desktop shortcut will be created, using which you can launch the application. After launching the application, you will get a control screen. In order to start the Turbo C++ Compiler, click on the “Start Turbo C++” link on the bottom right part of the window.

Turbo C for Windows Image 2

Before clicking on the Start Turbo C++ Link, you can check the Full Screen Mode option on the bottom left part of the control window. This option will allow you to directly start the Turbo C++ in full screen mode.

How to Configure Turbo C++?

After clicking on the Start Turbo C++ link, you will automatically get the Turbo C++ Window with its iconic blue screen.

TIP: To Toggle between window mode and full screen mode, use Alt + Enter.

Turbo C for Windows Image 3

After the Turbo C++ is launched, the first step you need to do is to make sure that all the directories associated with Turbo C++ are correct. For example, the directory INCLUDE contains all the header files like STDIO, CONIO, MATH, etc.

To check, go to Options in the Menu Bar (shortcut is Alt+o) and select ‘Directories’.

Download Turbo C for Windows Image 10

In our case the directories are as follows:

  • Include Directories: C:\TURBOC3\INCLUDE
  • Library Directories: C:\TURBOC3\LIB
  • Output Directory: C:\TURBOC3\SOURCE
  • Source Directories: C:\TURBOC3\SOURCE

Turbo C for Windows Image 4

Alternative Download for Windows 7

If you are still using Windows 7 or Windows 8 in your computer and if you want to install Turbo C in your Windows 7 system, then some users complained that the above method isn’t working properly. So, after some research, I found a new Turbo C Application which can run on Windows 7 machines.

To download Turbo C for Windows 7, go to this link and click on the “FREE DOWNLOAD” option.

Download Turbo C for Windows 7 Image 1

Two mirror links pop-up and after trying for sometime, I found that I had to use a VPN to download the file and that too only from the EU server.

Download Turbo C for Windows 7 Image 2

The latest version at the time writing this tutorial was “TurboC++ for Windows 7_v3.7.8.9major_release”. As you can see, I downloaded this in 2021 and the link is working.

Download Turbo C for Windows 7 Image 3

NOTE: If downloading from the above link doesn’t work, then you might have to use a VPN Connection. Try any free VPN extensions for Chrome and see if you are able to download it.

The installation is very simple, just follow the on-screen instructions. An advantage with this installation is that you can modify the installation location but the default location stays “C:\TurboC++\”.

Download Turbo C for Windows 7 Image 4

First Program in Turbo C++

After setting up the directories, you are ready to begin programming in Turbo C++. So, to start writing a program, go to File Tab and Click on New (you can use the keyboard shortcuts). A new editor window will be opened.

The first program we usually write in C Language is the Hello World. Without further ado, start typing the code. The program for printing “Hello, World!” is given below.

Test Code
#include<stdio.h>
#include<conio.h>
void main ()
{
clrscr();
printf(“Hello, World!”);
getch();
}

Turbo C for Windows Image 5

To save the file, click File –> Save or F2. Type in an appropriate name, like TEST.C (or TEST.CPP for C++ file). Compile the code by pressing Alt + F9. A small window will popup mentioning the result of the compilation (like success, error, warnings, etc.). After successful compilation, in order to run the program, enter Ctrl + F9. You will get the result in a new window.

Turbo C for Windows Image 6

You have successfully downloaded Turbo C++, installed it in your latest Windows System and written your first C Program.

In this tutorial, I have shown you how to download Turbo C for Windows, install Turbo C on any latest version of Windows (Windows 7, 8 or 10) and also how to write C Program in Turbo C.

Class 12 Computer Science MCQ set

  Class 12 Computer Science MCQ set According to the new curriculum and grid of NEB, there is an abrupt change in question pattern. Computer...