SQL DROP DATABASE Statement

DROP DATABASE Statement

The DROP DATABASE statement in SQL (Structured Query Language) is used to delete a database permanently.

SYNTAX

Syntax for DROP DATABASE in SQL

DROP DATABASE database_name;

Here database_name is the name of the database which you want to delete.


Example:

Below is the example for DROP DATABASE Statement in SQL

DROP DATABASE StudentInformation;

This statement deletes a database named StudentInformation.



NOTE: Be careful before dropping a database because this deletion would result in loss of data stored in the database.










SQL CREATE DATABASE Statement

SQL CREATE DATABASE Statement

The CREATE DATABASE statement in SQL (Structured Query Language) is used to create a database.


Syntax for CREATE DATABASE in SQL

CREATE DATABASE database_name;

Here database_name is the name of the database.

Example

Below is the example for CREATE DATABASE Statement in SQL

CREATE DATABASE StudentInformation;

This statement creates a database named StudentInformation.


SQL Tables will be created to store the data for the database.







SQL Data Definition Language (DDL)

Data Definition Language (DDL) in SQL:

A Data Definition Language or Data Description Language (DDL) is used to define data structures, especially it defines database schema.

The Data Definition Language DDL part of SQL permits database tables to create or delete. It also defines indexes (keys), it specifies links between tables, and also DDL imposes constraints between tables.

The most important DDL statements in SQL are given bellow:

  • CREATE DATABASE
               – The CREATE DATABASE Query is used to creates a new database

  • ALTER DATABASE
               - The ALTER DATABASE Query modifies a database

  • DROP DATABASE
               - The DROP DATABASE Query deletes a database


  • CREATE TABLE
               - The CREATE TABLE Query is used to create a new table

  • ALTER TABLE
               – The ALTER TABLE SQL Query modifies a table

  • DROP TABLE
               - DROP TABLE deletes a table

  • CREATE INDEX
               - CREATE INDEX creates an index (search key) for the data in the table

  • DROP INDEX
               - DROP INDEX Query deletes an index

We will see more about each SQL Statements and how to use these statements in your SQL Query in following SQL sessions.



SQL Data Manipulation Language (DML)

What is Data Manipulation Language (DML) in SQL

Data manipulation language (DML) is used for inserting, deleting and updating data in a database. Performing read-only queries of data is sometimes also considered a component of DML.

The most important Data Manipulation Language (DML) statements in SQL are given bellow:


  • SELECT
               – The Select Statement is used to extracts data from a database table


  • UPDATE
               – The Update Statement is used to update the data in a database table

  • DELETE
               – The Delete Statement is used to delete the data from a database table

  • INSERT INTO
               – The Insert Statement inserts new data into a database table


Most of the SQL Queries are common across all the database systems. We will learn more about each SQL Statements and how to use these statements in our SQL Queries in next sessions.




DML and DDL in SQL

What is DML and DDL in SQL

The Structured Query Language (SQL) is divided into two parts: They are The Data Manipulation Language (DML) and the Data Definition Language (DDL).


Using SQL Data manipulation language (DML) Queries we can insert, delete or update data in to the database tables. The Data definition language (DDL) is used to define the data structures in database example creating updating or deleting databases or creating /modifying tables schema.


We will see more about SQL Data Definition Language (DDL) and Data manipulation language (DML) statements in following sessions.



SQL Database Normalization

What is Database Normalization in SQL

Database normalization is the process of organizing data in a database to minimize data redundancy. There are two reasons of the normalization process:


  1. Eliminating redundant data, for example, storing the same data in more than one tables.
  2. Ensuring data dependencies make sense.


Both of these are worthy goals as they reduce the amount of space a database consumes and ensure that data is logically stored. Normalization consists of a series of guidelines that help guide you in creating a good database structure.

Normalization guidelines are divided into normal forms; think of form as the format or the way a database structure is laid out. The aim of normal forms is to organize the database structure so that it complies with the rules of first normal form, then second normal form, and finally third normal form.

  • First Normal Form (1NF)

  • Second Normal Form (2NF)

  • Third Normal Form (3NF)

  • Fourth Normal Form (4NF)

It's your choice to take it further and go to fourth normal form, fifth normal form, and so on, but generally speaking, third normal form is enough.





Data Integrity in SQL

What is Data Integrity in SQL:
Enforcing data integrity in RDBMS ensures the quality of the data in the database. For example, if an employee is entered with an EmployeeId value of 111, the database should not allow another employee to have an ID with the same value.
The following are the categories of the data integrity exist with each RDBMS:

  • Entity Integrity
  • Domain Integrity
  • Referential integrity
  • User-Defined Integrity


Entity Integrity In SQL:
Entity Integrity ensures There are no duplicate rows in a table. This can be achieved using constraints like UNIQUE, or creating IDENTITY COLUMN or adding PRIMARY KEY to the column.

Domain Integrity  In SQL:
The Domain Integrity Enforces valid entries for a given column by restricting the type using DATA TYPES, the format by using CHECK constraints and rules or the range of values by using CHECK Constrains, giving DEFAULT values , Adding foreign key constrains or adding NOT NULL definitions to the columns.

Referential integrity  In SQL:
By enforcing Referential integrity, Rows cannot be deleted, which are used by other records. In RDBMS referential integrity is the relationships between foreign keys and primary keys.

User-Defined Integrity  In SQL:
The User-Defined Integrity rules Enforces some specific business rules that do not fall into entity, domain or referential integrity.