
SQL Operations
After entering the SQLite shell, use SQL commands to create the table. CREATE TABLE: Create a new table. For my assignment, I will be making a table about athletes, so I enter the athletes after the CREATE TABLE command.
id INTEGER PRIMARY KEY AUTOINCRMENT: Creates a unique, auto-incrementing identification number for each athlete.
name TEXT NOT NULL: Store the name of the athlete. The NOT NULL constraint ensures that the column cannot be null.
sport TEXT NOT NULL: Store the sports played by athletes. Nor is it empty.
Country TEXT NOT NULL: The country the athlete represents. Nor is it empty.
Age INTEGER: Athlete’s age.
height REAL: Athlete’s height (for example, in meters).
Weight REAL: Athlete’s weight (for example, in kilograms).
INSERT INTO: Add new data to the athlete table.
Specify the fields: (name, sport, country, age, height, weight) to ensure data is only added to these fields. Unlisted id columns are automatically handled by the database.
VALUES: Contains the data of the specified columns in the same order.
SELECT: Retrieve data from the athlete table.
*: Select all fields in the table.
From Athlete: Displays all rows and columns from the Athlete table.
ALTER TABLE: Modify the structure of the existing athlete table.
ADD COLUMN team TEXT: Add a new field called team to store the team the athlete is on.
Update: Modify existing data in the athletes table.
SET team =: Update the team column to the value of the team it plays for.
WHERE name/country =: Ensures that only rows matching athlete name or country are updated.
Delete from athlete: Delete data from the athlete table.
WHERE name =: Only delete rows with matching athlete names.
2024-12-23 05:12:18