Mastering SQL: Practical Database Design and Query Examples

SQL Database Management: Supplier and Product Inventory

Defining the Inventory Schema (DDL)

We begin by setting up the database structure for tracking suppliers and their products. Note the use of PRIMARY KEY, FOREIGN KEY, and CHECK constraints for ensuring data integrity.

Supplier Table Creation

CREATE TABLE Supplier (
    SupplierID INT PRIMARY KEY,
    Name VARCHAR(100) NOT NULL,
    City VARCHAR(50)
);

Product Table Creation

CREATE TABLE Product (
    ProductID INT PRIMARY KEY,
    Name VARCHAR(100)
Read More

Programming Language Concepts: Binding, Scope, and Data Structures

Binding, Typing, and Namespaces

A binding is an association between an entity and an attribute, such as between a variable and its type or value, or between an operation and a symbol.

Variable Scope: Static vs. Dynamic

Variable Scope is the range of statements in which the variable is visible. A variable is visible in a statement if it can be referenced or assigned in that statement.

  • Static Scoping: The scope of a variable is determined prior to program execution and remains unchanged throughout (can
Read More

Fundamentals of Algorithm Design, Analysis, and Complexity Theory

Iterative Algorithms: Definition and Structure

An iterative algorithm repeatedly executes a set of instructions using loops (for, while, do-while) until a certain condition is satisfied. Instead of solving a problem directly in one step, the solution is approached gradually by repeating computations and updating variables.

Iterative algorithms rely on repetition (iteration) and are widely used for problems involving repeated calculations, searching, and optimization. Examples include Linear Search,

Read More

C Code for Knapsack, MST, and Shortest Path Algorithms

1. Fractional Knapsack Problem (Greedy Approach)

This implementation solves the Fractional Knapsack Problem using a Greedy Approach. Items are sorted based on their profit-to-weight ratio to maximize the total profit within the given capacity.

C Implementation

#include <stdio.h>
#include <stdlib.h>

struct Item {
    int weight, profit;
    float ratio;
};

// Comparison function for qsort: sorts items by ratio in descending order
int compare(const void *a, const void *b) {
    struct Item 
Read More

C++ Implementations of Core Algorithms: DP, Graph, Sort

Essential Algorithms Implemented in C++

Longest Common Subsequence (LCS)

The Longest Common Subsequence (LCS) problem is solved here using Dynamic Programming. It calculates the length and reconstructs the actual subsequence of two input strings.

#include <iostream>
#include <string>
#include <vector>
#include <algorithm> // For max function

using namespace std;

int main() {
    string X, Y;
    cout << "Enter first string: ";
    cin >> X;
    cout << "Enter 
Read More

Java EE Concepts: Interceptors, Hibernate, JPA, and Servlets

EJB Interceptors Explained

An interceptor is a class or method that intercepts EJB method calls or lifecycle events. It is used for common tasks like logging, security, transactions, and auditing. It helps avoid duplicate code and keeps business logic separate from system logic. Interceptors can be defined as a separate class or inside the bean. They use annotations to define behavior.

@AroundInvoke is used for method interception, while @PostConstruct and @PreDestroy are used for lifecycle interception.

Read More