Skip to content

Instantly share code, notes, and snippets.

View thevipulvats's full-sized avatar
💭
I may be slow to respond.

Vipul thevipulvats

💭
I may be slow to respond.
View GitHub Profile
/*
* PRIMARY KEYS IN SQL
* This script demonstrates the concepts and best practices for using primary keys in database design
*/
-- Primary Keys - Key Benefits:
-- They uniquely identify each record in a table
-- They ensure no duplicate records exist
-- They provide a reference point for relationships between tables
-- They optimize database performance for record retrieval
-- Database Normalization: 1NF, 2NF, and 3NF Demonstration
-- This SQL script demonstrates the process of normalizing a database through
-- First, Second, and Third Normal Forms using a bookstore database example.
-- Create and use bookstore database
CREATE DATABASE bookstore;
USE bookstore;
-- Original denormalized table
CREATE TABLE book_orders (
-- Foreign Keys in SQL: Database Relationships
-- =============================================
-- INTRODUCTION TO FOREIGN KEYS
-- A foreign key is a column or set of columns in one table that refers to the primary key in another table.
-- It creates a link between the two tables, establishing a parent-child relationship.
-- Parent table: Contains the primary key that is referenced
-- Child table: Contains the foreign key that references the primary key of the parent table
-- Purpose of Foreign Keys: Referential Integrity, Data Validation, Structured Relationships
-- SQL INNER JOIN Lecture
-- An INNER JOIN returns only the rows where there is a match in both tables based on the specified join condition.
-- If there's no match, the rows from both tables are excluded from the result set.
-- Create database
CREATE DATABASE db_inner_join;
USE db_inner_join;
-- Create authors table
CREATE TABLE authors (
-- GROUP BY Examples in SQL
-- =============================================
-- This file demonstrates various examples of using GROUP BY in SQL queries
-- for data summarization and aggregation operations.
-- Database Setup
-- =============================================
CREATE DATABASE db_for_group_by;
USE db_for_group_by;
-- =============================================
-- SQL FUNCTIONS DEMO SCRIPT
-- A comprehensive demonstration of various SQL functions
-- =============================================
-- =================
-- STRING FUNCTIONS
-- =================
-- Create and use database for string function examples
-- MySQL DISTINCT Tutorial
-- The DISTINCT clause eliminates duplicate rows from the result set
-- Syntax: SELECT DISTINCT column1, column2 FROM table_name;
-- Create and use the database
CREATE DATABASE EmployeeDB;
USE EmployeeDB;
-- Create employees table
CREATE TABLE employees (
-- MySQL Aliases Tutorial
-- Aliases are temporary names assigned to database tables, columns, or expressions
-- to make them more readable and manageable.
-- Create and use the database
CREATE DATABASE db16;
USE db16;
-- Create employees table
CREATE TABLE employees (
-- =============================================
-- MySQL LIMIT Clause Lecture
-- =============================================
-- 1. Setup and Sample Data
CREATE DATABASE db13;
USE db13;
-- Create products table
CREATE TABLE products (
/*
SQL Sorting and ORDER BY Tutorial
================================
This SQL script demonstrates various techniques for sorting data using ORDER BY
and includes examples ranging from basic to advanced sorting concepts.
*/
-- Section 1: Database and Table Setup
-- ----------------------------------
CREATE DATABASE db12;