SQL - (Structured Query Language)

SQL - (Structured Query Language)

Explaining it to you as a kid

Imagine you have a big box of toys at home, and you want to keep them organized. You decide to use special cards to sort them out. Each card has different information about a toy, like its name, color, size, and where it belongs in the box.

Now, SQL (pronounced as "sequel") is like a magic language you use to talk to the box and those cards. With SQL, you can ask questions like "Show me all the blue toys" or "Give me the names of all the toys that belong to you."

DBMS stands for Database Management System. Think of it as a helper who manages all those cards and the box. It helps you add new cards, find cards quickly, and keep everything neat and tidy.

RDBMS stands for Relational Database Management System. This is like a super organized way of managing your cards and box. It not only helps you keep track of toys but also helps you see how different toys are related to each other. For example, it helps you know which toy belongs to which kid, or which toys are similar to each other.

  • Card represents a table: Each card is like a table in a database. It contains information about a specific type of item, just like a table in a database contains rows and columns of related data.

  • Box represents a database: The box is like the overall database itself. It's the container that holds all the tables (or "cards") and keeps them organized. Just as you organize your toys in the box, a database organizes tables and data.

Data-types


  1. Numeric Types:

    • INTEGER: Whole numbers without decimal points.

    • FLOAT/REAL: Floating-point numbers with decimal points.

    • DECIMAL/NUMERIC: Exact numeric values with a specified precision and scale.

  2. Character String Types:

    • CHAR(n): Fixed-length character strings with a specified maximum length.

    • VARCHAR(n): Variable-length character strings with a specified maximum length.

    • TEXT: Variable-length character strings with no specified maximum length.

  3. Date and Time Types:

    • DATE: Date values in the format YYYY-MM-DD.

    • TIME: Time values in the format HH:MM:SS.

    • TIMESTAMP/DATETIME: Date and time values in the format YYYY-MM-DD HH:MM:SS.

  4. Boolean Type:

    • BOOLEAN: Represents true or false values.
  5. Binary Types:

    • BINARY(n): Fixed-length binary strings with a specified maximum length.

    • VARBINARY(n): Variable-length binary strings with a specified maximum length.

    • BLOB: Variable-length binary strings with no specified maximum length.

  6. Other Types:

    • ARRAY: Collection of elements of the same data type.

    • JSON: Stores JSON (JavaScript Object Notation) data.

    • XML: Stores XML (eXtensible Markup Language) data.

    • UUID: Universally Unique Identifier.

Now lets talk about few specific terminologies if we want to talk to that box because that box doesnt respond to our language it hence uses a special language namely structured query language

Following are the command types that are simplified for our usecases:

DDL : Data definition Language

  1. CREATE-Used to make something new, like creating a new table or database.

  2. ALTER-Used to change something existing, like adding a new column to a table.

  3. DROP-Used to delete something, like dropping a table or database.

  4. TRUNCATE-Used to remove all records from a table, but keeps the table structure.

  5. RENAME-Used to change the name of something, like renaming a table or column.

DML : Data Modification Language

  • SELECT: Used to retrieve data from one or more tables.

  • INSERT: Used to add new records (rows) into a table.

  • UPDATE: Used to modify existing records in a table.

  • DELETE: Used to remove existing records from a table.

  • MERGE: Used to perform insert, update, or delete operations based on specified conditions.

  • LOCK TABLE: Used to lock a table to prevent other users from accessing it concurrently, ensuring data integrity during certain operations.

DCL : Data Control Language

  • GRANT: Used to give specific privileges or permissions to users or roles on database objects, such as tables or views.

  • REVOKE: Used to take back previously granted privileges or permissions from users or roles on database objects, restricting their access.

TCL : Transaction Control Language

  • COMMIT: Saves all the changes made during the current transaction permanently to the database.

  • ROLLBACK: Undoes all the changes made during the current transaction and restores the database to its state before the transaction began.

  • SAVEPOINT: Sets a point within the current transaction to which you can later roll back.

  • RELEASE SAVEPOINT: Removes a savepoint that you previously defined within the current transaction.

SQL databases

No-SQL databases

mysql postgressql

mongodb

Did you find this article valuable?

Support Thirumalai by becoming a sponsor. Any amount is appreciated!