A database is a structured storage space where the data is kept in many tables in an organized way so that its contents can be easily accessed, managed, and updated.
A database management system or DBMS is system software that can create, retrieve, update, and manage a database. The Database Management System allows a user to interact with the database. There are various types of DBMS, such as relational, hierarchical, network, graph, or object-oriented.
RDMS stands for Relational Database Management System. It's the most common type of DBMS used for working with data stored in multiple tables and relations can be defined between the common fields of these tables.
SQL stands for Structured Query Language. It is a standard programming language used to communicate with relational database management systems (RDBMS). This includes fetching, updating, inserting, and removing data from tables in the database.
The various versions of SQL are also called SQL dialects. Some examples are Microsoft SQL Server, PostgreSQL, MySQL, SQLite, T-SQL, Oracle, and IBM DB2.
SQL is a standard language for retrieving and manipulating structured databases. MySQL is the world’s most popular and widely used open-source relational database management system like SQL Server, and Oracle that is used to manage SQL databases. It is lightweight and specially designed for web applications, developed by Oracle.
Data definition language (DDL): It defines the data structure that consists of commands like CREATE, ALTER, DROP, etc.
Data manipulation language (DML): It is used to manipulate existing data in the database. It consists of commands like SELECT, UPDATE, INSERT, etc.
Data control language (DCL): It controls access to the data stored in the database. It consists of commands - GRANT and REVOKE.
Transaction Control Language (TCL): It is used to deal with the transaction operations in the database. The commands in this category are COMMIT, ROLLBACK, SET TRANSACTION, SAVEPOINT, etc.
A Table is an organized collection of data stored in a tabular form i.e. rows and columns. Rows are horizontal and columns are vertical. The columns in a table are termed as fields and rows are termed as records.
Data Integrity defines the accuracy and consistency of data stored in a database. The data stored in the database must satisfy certain types of procedures (rules) when it is entered into the application or database. DBMS provides different ways to implement such types of constraints (rules).
Constraints are used to specify the rules concerning data in the table. It can be applied for single or multiple fields in an SQL table during the creation of the table
Auto increment keyword allows the user to create a unique number to be generated when a new record is inserted into the table. The Auto Increment feature is supported by all the Databases. Mostly this keyword can be used whenever PRIMARY KEY is used.
A primary key is a combination of the NOT NULL and UNIQUE constraints. The primary key uniquely specifies each record of the table. Each table should contain a primary key and there can only be one primary key constraint per table. For example, the ROLL Number can be treated as the primary key for a student in a university or college.
A foreign key is used to create a relationship between two tables by referencing a foreign key with the primary key of another table. The purpose of foreign keys is to keep various tables of a database.
The DEFAULT constraint is used to fill a column with default and fixed values. The value will be added to all new records when no other value is provided.
An index is simply a reference to data in a table and is used for storing its important parts and enabling faster data search and retrieval. These are useful for large databases.
SQL Joins is used to combine records (rows) from two or more tables in a SQL database based on a related column between the two.
There are different types of JOINs in SQL.
Normalization is used to minimize redundancy and dependency by organizing fields and tables of a database. This helps us in removing all the redundant data. Normalization breaks the table into small partitions by adding, deleting, or modifying fields and making a single table.
Normal Forms are used to eliminate or reduce redundancy in database tables. There are 6 normal forms, but the first three are the main.
When every attribute in a relation is a single-valued attribute, it is said to be in the first normal form. This should remove all the duplicate columns from the table.
A relation is in second normal form if it meets the first normal form’s requirements and does not contain any partial dependencies means it has no non-prime attribute that is dependent on any suitable subset of any table candidate key. It is done by setting a single column Primary Key.
If a relation meets the requirements for the second normal form and removes the columns that are not dependent on primary key constraints. Then it is said to be in the third normal form.
Denormalization is a database optimization technique in which we add redundant data to one or more tables by incorporating data from the related tables. This can help us avoid costly joins in a relational database. It is an optimization technique that is applied after normalization.
Denormalization is the process opposite of normalization as it introduces data redundancy and combines data from multiple tables.
A reserved character or a keyword is used in SQL queries to perform a specific operation. SQL operators are a combination of characters that are commonly used with the WHERE clause to set a condition (or conditions) for filtering the data.
A database object representing a set of SQL statements frequently used for a certain task. A function takes in some input parameters, performs calculations or other manipulations on them, and returns the result.
Aggregate functions – work on multiple, usually grouped records for the provided columns of a table, and return a single value (usually by group). For example – AVG(), SUM(), MIN() etc.
Scalar functions – work on each value and return a single value. For example – LEN(), ROUND(), NOW() etc.
SQL functions can be built-in (defined by the system) or user-defined (created by the user for their specific needs).
Local variables can be accessed only inside the function in which they were declared whereas global variables are declared outside any function stored in fixed memory structures and can be used throughout the entire program.
A view is a virtual table that consists of a subset of data contained in a table. Views are not virtually present, and it takes less space to store. The view can have data from one or more tables combined, and it is depending on the relationship.
A database query is a code written to get the information back from the database. The query can be designed in such a way that it matches our expectation of the result set.
A subquery is a query within another query. The outer query is called as main query, and the inner query is called the subquery. A subQuery is always executed first, and the result of the subquery is passed on to the main query.
A temporary name is given to a table or column while executing a certain SQL query. Aliases are used to improve the code readability and make the code more compact. An alias is introduced with the AS keyword. In the example, col_1 is the alias to the column.
SELECT col_1 AS column
FROM table_name;
A condition is imposed on a SQL query to filter the data to obtain the desired result. Some examples are WHERE, LIMIT, HAVING, LIKE, AND, OR, ORDER BY, etc.
The most common ones are FROM, GROUP BY, JOIN, WHERE, ORDER BY, LIMIT, and HAVING.
The ORDER BY statement in SQL is used to sort the fetched data in either ascending or descending according to one or more columns.
By default ORDER BY sorts the data in ascending order. The ASC keyword is used to sort the data in ascending order and the DESC keyword to sort the data in descending order.
HAVING is used to specify a condition for a group or an aggregate function used in the select statement. The HAVING clause selects rows after grouping.
The HAVING clause works on aggregated data after they are grouped, while the WHERE clause checks each row individually and selects before grouping. Unlike the HAVING clause, the WHERE clause cannot contain aggregate functions.
If both statements are present in a query then the order will be: WHERE – GROUP BY – HAVING.
COMMIT is applied when the transaction is successful and the commit command will permanently save the changes. The transaction cannot be undone after the COMMIT execution.
ROLLBACK occurs when the transaction is aborted. It undoes the changes by the current transaction and reaches its previous state after ROLLBACK.
You can add a column to a table using the ALTER TABLE statement in combination with ADD.
ALTER TABLE table_name
ADD column_name datatype;
You can rename a column name of a table using the ALTER TABLE statement in combination with RENAME COLUMN oldname TO newname.
You can prevent duplicate records by using the DISTINCT statement in combination with SELECT or by creating a unique key for that table.
You can insert multiple rows in a table using the INSERT INTO statement in combination with VALUES.
INSERT INTO TableName
VALUES (value_1, value_2, ..), (value_3, value_4,...),
(value_5, value_6, ..), ..;
Copyright © 2023 - Proleed Academy | All Rights Reserved.