Learning of SQL Day 2

Day 2: Basic SQL Syntax

Introduction:

  • Understanding the basic syntax of SQL is essential for writing queries to manage and retrieve data.

Key Concepts:

  • SQL Statements: Instructions to perform tasks.

  • Clauses: Components of SQL statements (e.g., SELECT, WHERE).

  • Keywords: Reserved words in SQL (e.g., SELECT, INSERT).

  • Identifiers: Names given to database objects like tables, columns.

  • Expressions: Combinations of values, operators, and SQL functions.

Basic SQL Commands:

  1. SELECT Statement:

    • Used to retrieve data from a database.

SQL
-- Select all columns from the Students table
SELECT * FROM Students;

-- Select specific columns from the Students table
SELECT FirstName, Age FROM Students;
  1. INSERT Statement:

    • Used to insert data into a table.

sql
-- Insert a single row of data into the Students table
INSERT INTO Students (StudentID, FirstName, LastName, Age)
VALUES (2, 'Jane', 'Smith', 22);
  1. UPDATE Statement:

    • Used to modify existing data in a table.

sql
-- Update the Age of the student with StudentID = 2
UPDATE Students
SET Age = 23
WHERE StudentID = 2;
  1. DELETE Statement:

    • Used to delete data from a table.

sql
-- Delete the student with StudentID = 1
DELETE FROM Students
WHERE StudentID = 1;

Practice Exercise:

  • Create a table named Courses with columns CourseID, CourseName, and Credits.

  • Insert three courses into the Courses table.

  • Write a query to select all courses.

  • Update the Credits for one of the courses.

  • Delete one course.

Post a Comment

0 Comments