Run sqlite3 company.db and create tables with the following fields at minimum (you may add additional fields if helpful for your project):
CREATE TABLE IF NOT EXISTS professionals ( id INTEGER PRIMARY KEY, name TEXT NOT NULL, image_ext TEXT NOT NULL );
CREATE TABLE IF NOT EXISTS categories ( id INTEGER PRIMARY KEY, name TEXT NOT NULL, image_ext TEXT NOT NULL );
CREATE TABLE IF NOT EXISTS services ( id INTEGER PRIMARY KEY, categoryid INTEGER, servicename TEXT NOT NULL, FOREIGN KEY (categoryid) REFERENCES categories(id) );
Check that the tables were created as expected using the .tables and .schema commands.
Use INSERT queries to add rows to the professionals, categories, and services tables corresponding to the values you used in Project Part 1. The syntax for INSERT is:
INSERT INTO table_name (column1, column2, ...) VALUES (value1, value2, ...);
For example:
INSERT
INTO professionals
(name, image_ext)
VALUES ('Batman', 'jpg');
Please do add the actual professionals you intend to use in your project, instead of Batman. However, you may want add Batman anyway since we will soon practice deleting rows.
You may notice that the id column was omitted. That is because the id, as a PRIMARY KEY column, is set to auto-increment with each row added.
You may also notice that we are storing only the file extension ("jpg" in the example above) in the image_ext field. This is because we will start auto-naming image files based on id and extension, and because storing filename data this way will slightly simplify an issue that we will run into in Project Part 4 when we create webforms to add professionals, service categories, and services (because when we store it this way, we do not need to get the id first before putting in the filename).
Use UPDATE queries to edit rows in any table until you are comfortable with the syntax, which is as follows:
UPDATE table_name SET column1=value1, column2=value2 WHERE row_condition;
For example:
UPDATE professionals SET name='I''m Batman' WHERE id=1;
After updating, run SELECT queries to check whether the data updated.
Cautionary Note: It would be considered better practice to use WHERE id=last_insert_rowid() rather than WHERE email='batman@batman.com' on an UPDATE or DELETE query because id numbers or other unique identifiers for the row condition are preferred unless there is a reason to do otherwise, so that you do not update unintended rows (unlike this example).
Use a DELETE query to delete rows in any table until you are comfortable with the syntax (feel free to INSERT unnecessary rows as needed so you can then delete them). The syntax is as follows:
DELETE FROM table_name WHERE row_condition;
For example:
DELETE FROM professionals WHERE id=1;
After deleting, run SELECT queries to check whether the data was deleted.
When done, use .quit or ctrl-Z to exit sqlite3.