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:
SELECT Statement:
Used to retrieve data from a database.
-- Select all columns from the Students table
SELECT * FROM Students;
-- Select specific columns from the Students table
SELECT FirstName, Age FROM Students;
INSERT Statement:
Used to insert data into a table.
-- Insert a single row of data into the Students table
INSERT INTO Students (StudentID, FirstName, LastName, Age)
VALUES (2, 'Jane', 'Smith', 22);
UPDATE Statement:
Used to modify existing data in a table.
-- Update the Age of the student with StudentID = 2
UPDATE Students
SET Age = 23
WHERE StudentID = 2;
DELETE Statement:
Used to delete data from a table.
-- Delete the student with StudentID = 1
DELETE FROM Students
WHERE StudentID = 1;
Practice Exercise:
Create a table named Courses with columns
CourseID,CourseName, andCredits.Insert three courses into the Courses table.
Write a query to select all courses.
Update the
Creditsfor one of the courses.Delete one course.
0 Comments