IT 402 | APS 2024
SQL COMMANDS through fishTable
1. Create the fishTable
CREATE TABLE fishTable (
sn INT PRIMARY KEY,
name VARCHAR(30),
seedDt DATE,
feedQty DECIMAL(6,2),
taste CHAR(1)
);
2. Add Four Rows of Imaginary Fish Data
INSERT INTO fishTable (sn, name, seedDt, feedQty, taste) VALUES
(1, “Goldfish”, “2023-01-01”, 15.50, “A”),
(2, “Betta”, “2023-02-01”, 10.00, “B”),
(3, “Guppy”, “2023-03-01”, 12.25, “A”),
(4, “Tetra”, “2023-04-01”, 14.75, “C”);
3. Display All Fields in Table
SELECT * FROM fishTable;
4. Delete a Record (Various Ways)
-- Delete using primary key
DELETE FROM fishTable WHERE sn = 2;
Page 1 of 3
IT 402 | APS 2024
-- Delete using name
DELETE FROM fishTable WHERE name = “Guppy”;
5. Single Line and Multi-Line Comment
-- This is a single-line comment
/* This is a
multi-line comment */
6. Update Data
UPDATE fishTable
SET feedQty = 20.00
WHERE name = “Goldfish”;
7. Organize Data by a Particular Field
-- Ascending order by feedQty
SELECT * FROM fishTable ORDER BY feedQty ASC;
Page 2 of 3
IT 402 | APS 2024
-- Descending order by feedQty
SELECT * FROM fishTable ORDER BY feedQty DESC;
8. Alter the fishTable
ALTER TABLE fishTable
ADD color VARCHAR(15) DEFAULT 'Unknown';
-- Drop a column
ALTER TABLE fishTable DROP COLUMN color;
9. Display Only Selected Fields
SELECT name, feedQty FROM fishTable;
10. Delete fishTable
DROP TABLE fishTable;
11. DDL Vs DML
Aspects DML (Data Manipulation Language) DDL (Data Definition Language)
Definition DML commands are used to manipulate DDL commands are used to define and
and manage data in a database. manage the structure of a database.
Examples INSERT, UPDATE, DELETE, SELECT CREATE, ALTER, DROP, DELETE, TRUNCATE
Note that SQL keywords written in uppercase are NOT CASE-SENSITIVE.
Page 3 of 3