564 attributed reviews in the last 3 years
Refreshingly small course sizes
Outstandingly good courseware
Whizzy online classrooms
Wise Owls only (no freelancers)
Almost no cancellations
We have genuine integrity
We invoice after training
Review 30+ years of Wise Owl
View our top 100 clients
Search our website
We also send out useful tips in a monthly email newsletter ...
Software ==> | Python (34 exercises) |
Topic ==> | Linking to SQL Server (1 exercise) |
Level ==> | Relatively easy |
Subject ==> | Python training |
This exercise is provided to allow potential course delegates to choose the correct Wise Owl Microsoft training course, and may not be reproduced in whole or in part in any format without the prior written consent of Wise Owl.
This will generate the database that you'll need to use in order to do this exercise (remember to refresh your list of databases to see it!). Note that any files provided are only to be used for exercises published on this website, and may not be reused or distributed in any form without the prior written permission of Wise Owl.
Create a Python program called Listing films.py. Type in a variation of the following code to link to the SQL Server Movies database in the above folder:
# the main Python module to link to SQL Server
import pyodbc
# connect to the movies database (this uses Windows
# authentication and assumes your SQL Server instance
# is called sql2019 on your currnet computer)
movies_database_connnection = pyodbc.connect(
r"Driver=SQL Server;"
r"Server=.\sql2019;"
r"Database=Movies_01;"
r"Trusted_Connection=yes;"
)
# create an SQL command to show 100 longest films
sql_query = "SELECT Title, RunTimeMinutes, OscarWins FROM Film ORDER BY RunTimeMinutes DESC"
# create a cursor to get this data
movies_cursor = movies_database_connnection.cursor()
movies_cursor.execute(sql_query)
# for each of these 100 longest films, show ones winning more than 7 Oscars
films = movies_cursor.fetchmany(100)
You can copy and paste this code into any Python program which you write whenever you want to link to a SQL Server database.
Now extend the program so that - out of the 100 longest films - it lists out those which won more than 7 Oscars:
Correlation in this case IS causation: long films really do win more Oscars!
Remember that no Intellisense will help you to complete your commands when referencing fields from an ODBC connection - it's up to you to remember what the columns are called, and type in their names correctly.
Save your program and close it down.
You can find other training resources for the subject of this exercise here:
Kingsmoor House
Railway Street
GLOSSOP
SK13 2AA
Landmark Offices
99 Bishopsgate
LONDON
EC2M 3XD
Holiday Inn
25 Aytoun Street
MANCHESTER
M1 3AE
© Wise Owl Business Solutions Ltd 2023. All Rights Reserved.