Basics of DBMS

Basics of DBMS

What are keys in DBMS?

What is DBMS?

  • Database Management System(DBMS) is software that manages a database used to store, access, and handle data in tables.

  • It also secures the data.

  • DBMS ends up storing everything in a file.

There are many DBMS software including MySQL, IBM DB2, Oracle, etc.

what is Database?

A database is a collection of data, which is organized and stored in a structured format electronically in a computer system. A database can store data in any form like tables etc based on the type of database. Oracle and MySQL are some examples of a database.

What is Relational Database?

Relational database stores the data in the form of tables and these tables consist of columns and rows. These tables are also called relations in relational databases and columns are called attributes and rows are called tuples or records.

What are Keys?

  • A tuple or row in a table or relation must have a minimum number of attributes or columns in order to be uniquely identified.

  • Let us take an example to understand this topic.

  • Let's take a customer table as an example for this topic.

  • In the above table what are the columns which are used to uniquely identify a row are keys that means if you take cust name in the above table we can't find a unique row as there will be many duplicate names in a database.

Types of keys-:

  • Simple Key -:

    A key with only one attribute is called a Simple Key. In the above customer table, you can say that Cust ID is the simple key, and also Cust name can be a simple key but not both in a set can be simple keys.

  • Compound Key -:

    A key with multiple attributes is called a Compound Key. In the above table, the Cust name and Cust Id in a set is a Compound key.

  • Candidate Key -:

    A set of all unique keys are called Candidate keys. These are important keys. You can find a unique row using Cust ID, so Cust ID is a candidate key and also you can find a unique row using {Cust Name and Cust Add}, so this set is called a candidate key.

  • Primary Key -:

    This is the most important key. The DB designer or DB administrator may select one key to maintain uniqueness from the candidate keys. An example in the above table is Cust ID, DB designer or DB administrator can take it as the primary key because it will follow the constraints of the primary key. If you want to learn about the constraints of these keys wait for the next blog. We can find a unique row using the customer ID.

  • Alternative or secondary Keys -:

    The keys that are not present in the Primary key but present in the candidate keys. As we took Cust ID as the Primary key, so the example of Alternative or secondary Keys is {Cust Name and Cust Add}.

  • Super Key -:

    The union of candidate keys and attributes is called Super keys. Ex-: {Cust Name and Cust Add} = {Cust Name} U {Cust Add}.

  • Foreign Key -:

    A field (or group of fields) in one table that refers to the PRIMARY KEY in another table is known as a FOREIGN KEY. Assume it as a pointer to an attribute in another table.

  • If you compare the purchase table and the customer table you can see a common column or attribute that is cust ID. So it is a foreign key. It points to the customer table from the purchase table.

Self-Referential Foreign Key -:

A field (or group of fields) in one table that refers to the PRIMARY KEY in the same table is known as a Self-Referential Foreign Key. Assume it as a pointer to an attribute in the same table.

In the above, the table Manager column is the foreign key and Emp ID is the primary key for the table. As both are present in the same table so Manager attribute is known as a Self-Referential Foreign Key.

Conclusion-:

  • This is my first blog, if you read this blog just give feedback on how is the blog.

  • Keys are the most important topic in the DBMS. These are used in further topics also.