Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1) Create table COUNTRY with the following colums:county_code Integercountry_Name Varchar(50) 2) Create table CITY with the following colums:county_code Integercity_code Integercity_name Varchar(50) 3) Two of the

1) Create table COUNTRY with the following colums:county_code Integercountry_Name Varchar(50) 2) Create table CITY with the following colums:county_code Integercity_code Integercity_name Varchar(50) 3) Two of the queries must include JOIN operation onebeing LEFT OUTER JOIN. Write SQL queries similar to { # LIKE keyword sql = "SELECT * FROM customers WHERE address LIKE '%way%'" c.execute(sql) myresult = c.fetchall() for x in myresult: print(x)

# Preventing SQL injection sql = "SELECT * FROM customers WHERE address = ?" adr = ("Park Lane 38", ) c.execute(sql, adr) myresult = c.fetchall() for x in myresult: print(x)

# ORDER BY name sql = "SELECT * FROM customers ORDER BY name" c.execute(sql) myresult = c.fetchall() for x in myresult: print(x)

# DELETE sql = "DELETE FROM customers WHERE address = 'Mountain 21'" c.execute(sql) c.execute("COMMIT") print(c.rowcount, "record(s) deleted")

# UPDATE sql = "UPDATE customers SET address = 'Canyon 123' WHERE address = 'Valley 345'" c.execute(sql) c.execute("COMMIT") print(c.rowcount, "record(s) affected")

#LIMIT number of rows to be displayed c.execute("SELECT * FROM customers LIMIT 3") myresult = c.fetchall() for x in myresult: print(x)

#LIMIT by starting from another position c.execute("SELECT * FROM customers LIMIT 5 OFFSET 2") myresult = c.fetchall() for x in myresult: print(x)

# JOIN

# First create dependant table c.execute("CREATE TABLE dependant (cust_id int, dep_name VARCHAR(50))") c.execute("INSERT INTO dependant (cust_id, dep_name) VALUES (1, 'Ayse Yilmaz')") c.execute("INSERT INTO dependant (cust_id, dep_name) VALUES (5, 'Veli Ayvaz')") c.execute("INSERT INTO dependant (cust_id, dep_name) VALUES (2, 'Okan Durmaz')") c.execute("COMMIT")

# SELECT with JOIN c.execute( "SELECT cus.id, cus.name, dep.dep_name\ FROM customers cus \ JOIN dependant dep ON cus.id = dep.cust_id" ) myresult = c.fetchall() for x in myresult: print(x)

# LEFT JOIN c.execute( "SELECT cus.id, cus.name, dep.dep_name\ FROM customers cus \ LEFT JOIN dependant dep ON cus.id = dep.cust_id" ) myresult = c.fetchall() for x in myresult: print(x)

#RIGHT JOIN not supported in SQLite yet. # Prevent SQL injection with LIKE operator #Display all fields from customers who live in an address including "way" in it in such a way to prevent SQL injection. sql = "SELECT * FROM customer WHERE address LIKE ?" adr = '%way%' c.execute(sql, (adr,)) myresult = c.fetchall() for x in myresult: print(x) }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2015 Porto Portugal September 7 11 2015 Proceedings Part 1 Lnai 9284

Authors: Annalisa Appice ,Pedro Pereira Rodrigues ,Vitor Santos Costa ,Carlos Soares ,Joao Gama ,Alipio Jorge

1st Edition

3319235273, 978-3319235271

More Books

Students also viewed these Databases questions

Question

Why does sin 2x + cos2x =1 ?

Answered: 1 week ago

Question

What are DNA and RNA and what is the difference between them?

Answered: 1 week ago

Question

Why do living creatures die? Can it be proved that they are reborn?

Answered: 1 week ago