March 08, 2026

Stop Memorizing SQL Part 3 : A Practical SQL Cheat Sheet for Beginners

 A Practical SQL Cheat Sheet for Beginners

When learning SQL, students often struggle to remember the correct syntax during exams or practice exercises. A simple cheat sheet can help quickly recall the most commonly used SQL patterns and commands. In this article, we provide a concise SQL reference that covers essential commands such as SELECT, INSERT, UPDATE, DELETE, and CREATE TABLE. This quick guide helps students translate English instructions into SQL queries with confidence and speed.

Basic Idea of Database

 

Word

Meaning

Database

Collection of tables

Table

Like an Excel sheet

Row

Record

Column

Field

 

 SQL Structure

Remember only 5 SQL words:

·        CREATE

·        SELECT

·        INSERT

·        UPDATE

·        DELETE

 

English → SQL Keywords

 

Word in Question

SQL

Show / Display

SELECT

Add / Enter

INSERT

Increase / Change

UPDATE

Remove / Strike off

DELETE

Create table

CREATE TABLE

 

  SQL Commands

 

Command

Formula

SELECT

SELECT + column + FROM + table

INSERT

INSERT INTO + table + VALUES

UPDATE

UPDATE + table + SET + change

DELETE

DELETE FROM + table + WHERE

 

 

Learning SQL does not have to begin with memorizing complex syntax. As we have seen in this series, the key is to first understand the intent of the instruction in plain English and then translate that action into the appropriate SQL command. Whether it is showing data, adding records, updating information, or creating tables, most SQL tasks follow simple and logical patterns. The best way to strengthen this skill is through practice—try converting everyday scenarios into SQL queries, such as managing a student list, tracking library books, or updating store inventory. The more you practice translating real-life instructions into SQL actions, the more natural and intuitive SQL will become. Over time, you will find that writing SQL is not about memorization, but about thinking logically and expressing that logic through simple database commands.

Part 2: Creating Tables and Choosing the Right Data Types

 

Stop Memorizing SQL Part 2: Creating Tables and Choosing the Right Data Types

Creating Tables and Choosing the Right Data Types

Before storing data in a database, we first need to create a table that defines the structure of the information. A database table is very similar to an Excel worksheet, where each column represents a specific type of data such as numbers, text, or dates. In this article, we will learn a simple step-by-step method to create tables and choose the correct data types using an easy decision rule. This approach makes it easier for beginners to understand how database structures are designed.


A table in a database is like an Excel worksheet.

An Excel worksheet has:

       Worksheet name

       Column names

       Rows of data

Similarly, a database table also has:

       Table name

       Column names

       Records (rows)

 

 

Table = Excel sheet

 

English sentence

Create a table called student with student id, name, class and stream.

Step 1: Give the Table Name

Decide the name of the table.

Example:
 
student


Step 2: Identify the Column Names

Columns are the fields that store information.

Example columns:

       Stud_id

       Name

       Class

       Stream


Step 3: Choose the Correct Data Type

We must decide what type of data each column will store.

Use this simple 3-Question Rule:

Question 1: Is it a number?
 ➡ Use
INT

Question 2: Is it text or words?
 ➡ Use
VARCHAR

Question 3: Is it a date?
 ➡ Use
DATE

 

Column

Data Type

Reason

Stud_id

INT

Number

Name

VARCHAR

Text

Class

INT

Number

Stream

VARCHAR

Text

 

Which datatype to choose?

 

3-question rule:

Question 1: Is it a number?
 → INT

Question 2: Is it text?
 → VARCHAR

Question 3: Is it date?
 → DATE

 

Step 4: Write the SQL Syntax

  1. Write CREATE TABLE followed by the table name

  2. Write column names with their data types

  3. Separate columns using comma (,)

  4. Do not put comma after the last column

 

 

General syntax:

 

CREATE TABLE table_name

(

column_name datatype,

column_name datatype,

column_name datatype

);

 

Step 5 - Final result

 

CREATE TABLE student

(

Stud_id INT,

Name VARCHAR(30),

Class INT,

Stream VARCHAR(20)

);

 

Part 3 : A Practical SQL Cheat Sheet for Beginners

 

Part 1: Understanding the core SQL commands and how to map English actions to SQL operations


Stop Memorizing SQL Part 1: Understanding the core SQL commands and how to map English actions to SQL operations

 Guide to write SQL using English meanings

Many beginners find SQL difficult because they try to memorize syntax instead of understanding the meaning of database operations. In reality, SQL is very close to everyday English instructions. Words like show, add, remove, or change directly map to SQL commands such as SELECT, INSERT, DELETE, and UPDATE. In this article, we will learn how to identify action words in a question and translate them into the correct SQL command. This simple approach helps students write SQL queries even without remembering complex syntax.

 

English Meaning

SQL Keyword

What it does

Show / Display

SELECT

Read data

Add / Insert / Enter

INSERT

Add new row

Change / Increase / Modify

UPDATE

Modify data

Remove / Delete / Strike off

DELETE

Remove row

 

 4 step method to Create SQL query,  first identify the action word in the question.

 1️⃣ Identify the Action Word

 2️⃣ Identify the Table Name

 3️⃣ Identify the Condition (Which record?)

4️⃣ Write SQL using minimum syntax

Always end final SQL  with “;” ( semicolon)

Example:

Question 1

Strike off the record of student Rahul with student_id 100.

Step 1 – Identify Action

Strike off → DELETE

Step 2 – Table

student

Step 3 – Condition

student_id = 100

Step 4 – SQL using minimum syntax

DELETE FROM student

WHERE stud_id = 100;

 

SQL Part

Meaning

DELETE

remove

FROM student

from student table

WHERE

which record

stud_id = 100

student id 100

 

Question 2

 Add another student who has been admitted with the following details :

 Stud_id – 123

Name – Rajeev

Class – 12

Stream – Science

 

Step 1 – Identify Action

AddINSERT

Step 2 – Table

student

Step 3 – VALUES

(123,'Rajeev',12,'Science')

Step 4 – SQL using minimum syntax

INSERT INTO student

VALUES (123,'Rajeev',12,'Science');

  

SQL

Meaning

INSERT INTO

add data

student

table

VALUES

New data

 

Question 3

 Increase English marks by 10% of student 123

Step 1 – Identify Action

Increase → UPDATE

Step 2 – Table

student

Step 3 – Condition

student_id = 123

Step 4 – SQL using minimum syntax

UPDATE student

SET English = English * 1.10

Where student_id = 123;

 

SQL

Meaning

UPDATE

change data

SET

modify column

English * 1.10

increase 10%

 

English → SQL Dictionary

 

English Phrase

SQL

show all records

SELECT *

show specific columns

SELECT column

add record

INSERT

remove record

DELETE

modify record

UPDATE

where student id =

WHERE

 

English commands ->  SQL Keyword

 

English

SQL Keyword

Show student data

SELECT

Add new student

INSERT

Remove student

DELETE

Change marks

UPDATE

  

 

Word in Question

SQL

display / show

SELECT

add / enter

INSERT

increase / change

UPDATE

remove / strike off

DELETE

 

Part 2: Creating Tables and Choosing the Right Data Types

Stop Memorizing SQL: Learn to Translate English Sentences into SQL


Stop Memorizing SQL: Learn to Translate English Sentences into SQL

 

Introduction


Many beginners struggle with SQL because they try to memorize syntax instead of understanding the logic behind database operations. However, SQL is actually very close to the English language. Most database tasks can be understood simply by identifying the action being performed and translating it into the appropriate SQL command.

In this three-part series, we will learn a simple technique to translate English instructions into SQL queries. This approach is especially useful for students and beginners who are just starting with databases.

Instead of focusing on complex syntax, we will focus on thinking in English first and then mapping those instructions to SQL commands such as SELECT, INSERT, UPDATE, DELETE, and CREATE TABLE.

The series is organized into three parts:

  • Part 1: Understanding the core SQL commands and how to map English actions to SQL operations

  • Part 2: Creating tables and choosing the correct data types using a simple decision method

  • Part 3: A practical SQL cheat sheet that helps students quickly recall the most important SQL patterns

By the end of this series, readers will be able to read a simple English instruction and confidently write the corresponding SQL query.

https://avishkarm.blogspot.com/2026/03/stop-memorizing-sql-part-1.html

May 14, 2025

Fashion Catalog Similarity Search using Datastax AstraDB Vector Database

DataStax Astra DB's vector database capabilities can be leveraged to build an efficient fashion catalog similarity search, enabling users to find visually similar clothing items based on uploaded catalog descriptions. 


Product descriptions and other relevant text associated with the fashion items (e.g., tags, categories) can be converted into vector embeddings using a text embedding model (like SentenceTransformers).


from cassandra.cluster import Cluster

from cassandra.auth import PlainTextAuthProvider


# Read environment variables

secure_connect_bundle_path = os.getenv('ASTRA_DB_SECURE_CONNECT_BUNDLE')

application_token = os.getenv('ASTRA_DB_TOKEN')


# Setup authentication provider

auth_provider = PlainTextAuthProvider('token', application_token)


# Connect to the Cassandra database using the secure connect bundle

cluster = Cluster(

    cloud={"secure_connect_bundle": secure_connect_bundle_path},

    auth_provider=auth_provider

)

session = cluster.connect()


# Define keyspace

keyspace = "catalog"

v_dimension = 5


# Set the keyspace

session.set_keyspace(keyspace)


# Verify connection by querying the system.local table

rows = session.execute("SELECT release_version FROM system.local")

for row in rows:

    print(f"Connected to Cassandra, release version: {row.release_version}")


# Print the current keyspace

current_keyspace = session.execute("SELECT keyspace_name FROM system_schema.keyspaces WHERE keyspace_name = %s", [keyspace])

for row in current_keyspace:

    print(f"Connected to keyspace: {row.keyspace_name}")


print("Connected to AstraDB and keyspace successfully!")


session.execute((

    "CREATE TABLE IF NOT EXISTS {keyspace}.ProductDescVectors (ProductId INT PRIMARY KEY, ProductDesc TEXT, ImageURL text, CatalogVector VECTOR<FLOAT,{v_dimension}>);"

).format(keyspace=keyspace, v_dimension=v_dimension))


session.execute((

    "CREATE CUSTOM INDEX IF NOT EXISTS idx_ProductDescVectors "

    "ON {keyspace}.ProductDescVectors "

    "(CatalogVector) USING 'StorageAttachedIndex' WITH OPTIONS = "

    "{{'similarity_function' : 'cosine'}};"

).format(keyspace=keyspace))


text_blocks = [

    (1, "United colors of Benetton Men White Boxer Trunks","UndercolorsofBenetton-Men-White-Boxer_b4ef04538840c0020e4829ecc042ead1_images.jpg", [-0.0711570307612419, 0.0490173473954201, -0.0348679609596729, -0.0208837632089853, 0.0250527486205101]

),

    (2, "Turtle Men Check Red Shirt","Turtle-Men-Check-Red-Shirt_4982b2b1a76a85a85c9adc8b4b2d523a_images.jpg" ,[-0.0678209140896797, 0.0918413251638412, 0.0087888557463884, -0.0005505480221473, 0.0586152337491512]),

    (3, "United Colors of Benetton Men White Check Shirt","United-Colors-of-Benetton-Men-White-Check-Shirt_13cfaff26872c298112a8e7da15c1e1d_images.jpg" ,[-0.0697127357125282, 0.0486216545104980, -0.0169006455689669, -0.0160229168832302, 0.0137890130281448]

),

 (4, "United Colors of Benetton Men Check White Shirts","UnitedColorsofBenetton-Men-Check-White-Shirts_5bd8cae4fc61052a6f00cfcd69c4a936_images.jpg" ,[-0.0499644242227077, 0.0566278323531151, -0.0294290613383055, -0.0070271748118103, 0.0289674568921328]

),

    (5, "Wrangler-Men-Broad-Blue-Shirt","Wrangler-Men-Broad-Blue-Shirt_8211520250143786-1.jpg" ,[-0.0581886917352676, 0.0378338471055031, 0.0425588376820087, -0.0423909239470959, 0.0186673272401094]

)

]

for block in text_blocks:

    id, text, text,vector = block

    session.execute(

        f"INSERT INTO {keyspace}.ProductDescVectors(ProductId, ProductDesc, ImageURL,CatalogVector) VALUES (%s, %s,%s, %s)",

        (id, text, text,vector)

    )


/*

Performing Catalog Similarity Search:

User Enters Text Description: If a user provides a text description, generate its vector embedding using the appropriate text embedding model like llama_index.embeddings.huggingface

Vector Search in Astra DB: Use Astra DB's vector search functionality to find the most similar embeddings in your database to the user's query embedding.

*/

ann_query = (

    f"SELECT  ProductDesc, ImageURL,similarity_cosine(CatalogVector, [0.15, 0.1, 0.1, 0.35, 0.55]) as similarity FROM {keyspace}.ProductDescVectors "

    "ORDER BY ProductImageVector ANN OF [0.15, 0.1, 0.1, 0.35, 0.55] LIMIT 2"

)

for row in session.execute(ann_query):

    print(f"[{row.productdesc}\" (sim: {row.similarity:.4f})")


    # Print success message

    

print("Catalogs with semantic match.")

/*


Example scenario:

A user wants more fashion products similar to "United Colors of Benetton Men Check White Shirts". 

The application:

Generates a vector embedding of the "United Colors of Benetton Men Check White Shirts" text.

Performs a vector search in Astra DB to find fashion items with similar catalog(text) embeddings.

Retrieves and displays the details of the most similar catalog, including similar brand,styles, colors, and potentially complementary items like shoes or accessories. 


Retrieve Matching Items: Astra DB returns the IDs of the fashion items corresponding to the most similar embeddings.


Display Results: Retrieve the full details (images, descriptions, etc.) of the matching fashion items from Astra DB and display them to the user. 

*/

ann_query_matching = (

    f"SELECT  ProductDesc, ImageURL,similarity_cosine(CatalogVector, [-0.0499644242227077, 0.0566278323531151, -0.0294290613383055, -0.0070271748118103, 0.0289674568921328]) as similarity FROM {keyspace}.ProductDescVectors "

    "ORDER BY CatalogVector ANN OF [-0.0499644242227077, 0.0566278323531151, -0.0294290613383055, -0.0070271748118103, 0.0289674568921328] LIMIT 2"

)

for row in session.execute(ann_query_matching):

    print(f"[{row.productdesc}\" (sim: {row.similarity:.4f})")

    

print("Data with similar match.")


Benefits of using Astra DB for fashion similarity search:

Scalability and Performance: Astra DB is designed for high-throughput, low-latency operations, making it suitable for large fashion catalogs and real-time search.

Simplified Architecture: Astra DB can store both your product data and vector embeddings, eliminating the need for separate vector databases.

Cost-Effectiveness: Astra DB offers serverless options, reducing the need for infrastructure management and associated costs.

Integration with GenAI Applications: Astra DB works seamlessly with tools like LangChain for building generative AI applications, potentially enabling features like fashion recommendations, chatbots, and more. 


Stop Memorizing SQL Part 3 : A Practical SQL Cheat Sheet for Beginners

 A Practical SQL Cheat Sheet for Beginners When learning SQL, students often struggle to remember the correct syntax during exams or practic...