SQL Activity Worksheet for Students
SQL Activity Worksheet for Students
To create a database named SchoolDB, the SQL command is: CREATE DATABASE SchoolDB; To create a table named Students with specified columns and constraints, use: CREATE TABLE Students (StudentID INT PRIMARY KEY, FullName VARCHAR(50), Age INT, Course VARCHAR(30)) These commands analyze how databases and tables are defined with structures and constraints.
Altering data structures involves SQL commands like ALTER TABLE to add new columns or change constraints. For example: ALTER TABLE Students ADD COLUMN Email VARCHAR(50) Adapting such commands ensures databases meet new requirements, allowing efficient scaling and data management.
Primary keys ensure each record in a table is unique, as demonstrated in the Students table where StudentID is a primary key . These constraints prevent duplicate entries, maintaining data integrity and aiding table design by establishing clear relationships and accessibility.
A typical SQL workflow involves: 1) Creating databases and tables (CREATE DATABASE/CREATE TABLE), 2) Inserting records (INSERT INTO), 3) Querying for data (SELECT), 4) Updating records (UPDATE), and 5) Deleting records (DELETE). These operations provide comprehensive record management and data interaction.
Using SELECT statements to retrieve specific columns like FullName and Course (e.g., SELECT FullName, Course FROM Students) enhances performance and efficiency by minimizing data load . This approach conserves resources and improves query speed compared to fetching entire datasets.
To retrieve all records from the Students table, the SQL command is: SELECT * FROM Students; To display specific columns such as FullName and Course, use: SELECT FullName, Course FROM Students; These commands illustrate basic data retrieval techniques and column selection.
To insert records into the Students table, the SQL commands are: INSERT INTO Students (StudentID, FullName, Age, Course) VALUES (1, 'Maria Santos', 20, 'BSIT'), (2, 'Juan Dela Cruz', 21, 'BSCS'), (3, 'Ana Lopez', 19, 'BSHM') This command synthesizes the insertion of multiple records efficiently.
To find students older than 19, the SQL command is: SELECT * FROM Students WHERE Age > 19; This command analyzes how SQL uses conditions to filter database records.
To delete Ana Lopez from the Students table, the SQL command is: DELETE FROM Students WHERE FullName = 'Ana Lopez'; This command evaluates the impact of permanent data removal on data integrity and record management.
To update Maria Santos' course to 'BSCS', use: UPDATE Students SET Course = 'BSCS' WHERE FullName = 'Maria Santos'; This command demonstrates the synthesis of data manipulation to reflect changes in the database.