Exploration of Database Fundamentals and SQL Databases
Hello Techie! Today we're diving into the world of databases and database management systems. Databases play an important role in managing and organizing vast volumes of data efficiently. Understanding the basics of databases and database management systems (DBMS) is crucial for anyone navigating the data-driven landscape.
Introduction :
A Database is like a digital collection of information. It help us to store, fetch, delete or analyse data quickly for making smarter decisions. Think of as a way to neatly organise data in tables. schemas, views and reports.
The Database Management System (DBMS) is a software tool which is used to manage our data which is stored in database. Examples of popular databases are Oracle, MySQL, PostgreSQL, MongoDB, InfluxDB etc.
You can check out the ranking according to popularity and information of any database management system by clicking here.
Accessing a database directly isn't common; instead, we use a Database Management System. DBMS is a software application responsible for performing various operations on the database, such as inserting, creating, finding, and deleting data.
Types of Database :
Generally database are classified as Relational and Non-Relational (NoSQL).
A Relational Database is a type of database that organizes and stores data in tables with rows and columns. In this structured system, each row represents a record, and each column represents a specific attribute or field of that record. The tables are interconnected based on relationships between the data, providing a clear and efficient way to manage and retrieve information. Relational databases use a standardized query language, often SQL (Structured Query Language), to perform operations such as inserting, updating, querying, and deleting data.
Examples of relational database management systems (RDBMS) include Oracle, MySQL, PostgreSQL,, Microsoft SQL Server etc.
A Non-relational database, often referred to as NoSQL (Not Only SQL), is a type of database that doesn't follow the traditional tabular structure of relational databases. Unlike relational databases, which use tables and predefined schemas, non-relational databases are more flexible and can handle a variety of data types and structures. They are particularly useful for managing large sets of distributed data and are designed to scale horizontally to accommodate growing amounts of information.
Examples of non-relational databases include MongoDB, Cassandra, Redis, etc.
SQL (Structural Query Language):
We use SQL to work with reational DBMS.
SQL, a widely known database language, empowers us to execute operations on existing databases and create new ones. It employs specific commands such as Create, Drop, Insert, and others to accomplish various tasks.
These SQL commands are primarily classified into five categories, namely:
1. DDL (Data Defination Language)
- CREATE: This command is used to create a new database or its objects such as tables, indexes, functions, views, stored procedures, and triggers.
- ALTER: This command is used to modify the structure of the database. It can be used to add, modify, or delete columns in an existing table.
- ADD: This sub-command is used to add a new column to an existing table.
- RENAME: This sub-command is used to rename an object that already exists in the database.
- DROP: This sub-command is used to delete an object from the database.
- TRUNCATE: This command is used to remove all records from a table, including all spaces allocated for the records are removed. It is used to permanently delete data and does auto-commit on rollback.
2. DML (Data Manupilation Language)
- INSERT: This command is used to insert new data into a table.
- DELETE: This command is used to delete data from a table. By calling rollback, data will be retained temporarily.
- UPDATE: This command is used to modify existing data in a table.
TRUNCATE : Used to permanently delete data (auto commit on rollback)
DELETE : To temporary delete data . By calling rollback data will retain
3. DCL (Data Control Language)
- GRANT: This command is used to give users access privileges to the database.
- REVOKE: This command is used to withdraw the user’s access privileges given by using the GRANT command.
4. TCL (Transaction Control Language)
It is a set of SQL commands that can be used to manage transactions in a database. A transaction is a sequence of operations that are executed as a single unit of work. TCL commands are used to manage the changes made by DML statements.
- COMMIT: This command is used to save all the transaction-related changes permanently to the disk.
- ROLLBACK: This command is used to undo the changes made to the database since the last commit.
- SAVEPOINT: This command is used to set a savepoint within a transaction.
5. DQL (Data Query Language)
It is an essential tool for anyone working with databases, as it allows you to interact with your data in a meaningful way.
- SELECT : This command is used to retrieve data from one or more tables in a database. It is used for performing queries on the data within schema objects.
- FROM: This clause helps you identify the source of data.
SELECT and FROM are mandatory clauses.
Here are some optional clauses that can be used
- WHERE: This clause filters the data.
- GROUP BY: This clause groups the filtered data into buckets.
- HAVING: This clause filters the result of GROUP BY.
- ORDER BY: This clause orders the result.
What is Keys in SQL ?
1. Primary Key (PK):
Primary Key(PK) is a column (or set of columns) in a table that uniquely identifies each row. (a unique id).
There is only 1 PK & it should be NOT null.
2. Foreign Key (FK):
A Foreign Key(FK) is a column (or set of columns) in a table that refers to the primary key in another table.
There can be Multiple FKs.
FKs can have Duplicate & Null values.
What is constrains in SQL Database ?
1. NOT NULL Constraint:
2. UNIQUE Constraint:
3. PRIMARY KEY Constraint:
4. FOREIGN KEY Constraint:
5. CHECK Constraint:
6. DEFAULT Constraint:
Joins in SQL
1. INNER JOIN:
2. LEFT (OUTER) JOIN:
3. RIGHT (OUTER) JOIN:
4. FULL (OUTER) JOIN:
5. LEFT EXCLUSIVE Join :
6. RIGHT EXCLUSIVE Join:
Wrapping Up
I'm not only here to chat but also to listen to you! I'd appreciate your feedback on this article and any suggestions for making it better. Let's work together to make understanding IoT easier. Let's discover the potential of IoT together!
Don't forget to share this article with your friends.
Join the conversation