SQL : Structured Query Language

Structured Query Language (SQL) is a specialized programming language for managing relational database data. It allows users to store, manipulate, and retrieve data efficiently in databases like MySQLSQL ServerOracle, and more.

SQL is a tool for organizing, managing, and retrieving archived data from a database.

When data needs to be retrieved from a database, SQL is used to make the request. The DBMS processes the SQL query retrieves the requested data and returns it to us. Rather, SQL statements describe how a collection of data should be organized or what data should be extracted or added to the database.

In common usage, SQL encompasses DDL and DML commands for CREATE, UPDATE, MODIFY, or other operations on database structure.

Key Concepts of SQL :-

Databases –

A database is an organized collection of structured information, or data, typically stored electronically in a computer system. A database is usually controlled by a database management system (DBMS). Together, the data and the DBMS, along with the applications that are associated with them, are referred to as a database system, often shortened to just database.

Data within the most common types of databases in operation today is typically modeled in rows and columns in a series of tables to make processing and data querying efficient. The data can then be easily accessed, managed, modified, updated, controlled, and organized. Most databases use structured query language (SQL) for writing and querying data.

Table –

A database table is a structured format for organizing and storing data in a relational database. Each table consists of rows and columns, where:

  • Rows: Also known as records, each row represents a single, implicitly structured data item in a table.
  • Columns: Also known as fields, each column represents a specific attribute of the data. Each column has a name and a data type.

Key Elements of a Database Table:

1 . Table Name: Each table has a unique name within a database that identifies the table.

2 . Columns (Fields):

  • Column Name: The name of the column.
  • Data Type: The type of data that the column can hold (e.g., integer, varchar, date).
  • Constraints: Rules applied to the data in the column (e.g., NOT NULL, UNIQUE, PRIMARY KEY).

3 . Rows (Records):

  • Each row in the table contains a unique instance of data for the columns defined in the table.
  • Rows can be added, modified, and deleted using SQL commands.

Example of a Database Table

Consider a table named Employees:

EmployeeID FirstName LastName BirthDate HireDate Department
1JohnDoe1985-06-012010-01-15Sales
2JaneSmith1990-07-232012-03-22Marketing
3SamBrown1982-12-112008-11-30HR
4LisaJohnson1988-09-052015-07-14IT
  • EmployeeID: An integer column serving as the primary key, uniquely identifying each employee.
  • FirstName: A varchar column containing the first name of the employee.
  • LastName: A varchar column containing the last name of the employee.
  • BirthDate: A date column containing the birthdate of the employee.
  • HireDate: A date column containing the hire date of the employee.
  • Department: A varchar column containing the department where the employee works.

Common SQL Commands for Tables:

  • Create Table: Defines a new table and its columns.

CREATE TABLE Employees (
EmployeeID INT PRIMARY KEY,
FirstName VARCHAR(50),
LastName VARCHAR(50),
BirthDate DATE,
HireDate DATE,
Department VARCHAR(50)
);

  • Insert Data: Adds new rows to a table.

INSERT INTO Employees (EmployeeID, FirstName, LastName, BirthDate, HireDate, Department)
VALUES (1, 'John', 'Doe', '1985-06-01', '2010-01-15', 'Sales');

  • Select Data: Retrieves data from a table.

SELECT * FROM Employees;

  • Update Data: Modifies existing data in a table.

UPDATE Employees
SET Department = 'Finance'
WHERE EmployeeID = 1;

  • Delete Data: Removes data from a table.

DELETE FROM Employees
WHERE EmployeeID = 1;

  • Drop Table: Deletes a table and all of its data.

DROP TABLE Employees;

These commands allow for the creation, modification, and management of database tables and the data within them.