The ever-useful “customer orders product” example again- there is always somethi
ID: 2246693 • Letter: T
Question
The ever-useful “customer orders product” example again- there is always something new to discover. Design the table that that will represent the order class in figure 9-14. Consider constraints, primary and foreign keys, and updating rules. Ex. 9.1
Hello, my name is Steven going a BA in computer science, I need help with this question. I need help on how to begin. Do we need to have the table to query language or do we need to make a table to represent the order class?
CHAPTER 9 MORE ON KEYS AND CONSTRAINTS TESTING YOUR UNDERSTANDING Exercise 9-1 The ever-useful customer orders product" example again-there is always something new to discover. Design the table that will represent the Order class in Figure 9-14. Consider constraints, primary and foreign keys, and updating rules. Customer customerlD last name 1.1 0.n Order date Product product name first name 11 0.n quantity n .1 current price Figure 9-14. Model for customers placing orders Exercise 9-2Explanation / Answer
Database concepts::-
When you first look at a database it looks like a spreadsheet with multiple sheets. The primary data structures in a database are: tables, rows, and columns.
In technical descriptions of relational databases the concepts of table, row, and column are more formally referred to as relation, tuple, and attribute, respectively.
Creating a database table
Databases require more defined structure than Python lists or dictionaries1.
When we create a database table we must tell the database in advance the names of each of the columns in the table and the type of data which we are planning to store in each column. When the
database software knows the type of data in each column, it can choose the most efficient way to store and lookup the data based on the type of data.
mport sqlite3
conn = sqlite3.connect('music.sqlite3')
cur = conn.cursor()
cur.execute('DROP TABLE IF EXISTS Tracks ')
cur.execute('CREATE TABLE Tracks (title TEXT, plays INTEGER)')
conn.close()
.....................................
1.For creating a table
CREATE TABLE Tracks (title TEXT, plays INTEGER)
2. To insert a row into a table, we use the SQL INSERT command:
INSERT INTO Tracks (title, plays) VALUES ('Mylove', 23)
SELECT title,plays FROM Tracks ORDER BY title
To remove a row, you need a WHERE clause on an SQL DELETE statement. The WHERE clause determines which rows are to be deleted:
DELETE FROM Tracks WHERE title = 'My Way'
It is possible to UPDATE a column or columns within one or more rows in a table using the SQL UPDATE statement as follows:
UPDATE Tracks SET plays = 16 WHERE title = 'My Way'
The UPDATE statement specifies a table and then a list of fields and values to change after the SET keyword and then an optional WHERE clause to select the rows that are to be updated.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.