This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ python | |
>>> from sqlalchemy import create_engine | |
>>> engine = create_engine("mssql+pyodbc://sqladmin:[email protected]:1433/adventureworks?driver=ODBC+Driver+17+for+SQL+Server") | |
>>> con = engine.connect() | |
>>> rows = con.execut('SELECT TOP 10 * FROM SalesLT.ProductCategory') | |
>>> [print(row) for row in rows] | |
(1, None, 'Bikes', 'CFBDA25C-DF71-47A7-B81B-64EE161AA37C', datetime.datetime(2002, 6, 1, 0, 0)) | |
(2, None, 'Components', 'C657828D-D808-4ABA-91A3-AF2CE02300E9', datetime.datetime(2002, 6, 1, 0, 0)) | |
(3, None, 'Clothing', '10A7C342-CA82-48D4-8A38-46A2EB089B74', datetime.datetime(2002, 6, 1, 0, 0)) | |
(4, None, 'Accessories', '2BE3BE36-D9A2-4EEE-B593-ED895D97C2A6', datetime.datetime(2002, 6, 1, 0, 0)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sqlalchemy import create_engine | |
def query_categories(): | |
engine = create_engine( | |
"mssql+pyodbc://sqladmin:[email protected]:1433/adventureworks?driver=ODBC+Driver+17+for+SQL+Server") | |
# The with statement cleans up the connection resource for us. | |
with engine.connect() as con: | |
rows = con.execute('SELECT TOP 10 * FROM SalesLT.ProductCategory') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ python query.py | |
(1, None, 'Bikes', 'CFBDA25C-DF71-47A7-B81B-64EE161AA37C', datetime.datetime(2002, 6, 1, 0, 0)) | |
(2, None, 'Components', 'C657828D-D808-4ABA-91A3-AF2CE02300E9', datetime.datetime(2002, 6, 1, 0, 0)) | |
(3, None, 'Clothing', '10A7C342-CA82-48D4-8A38-46A2EB089B74', datetime.datetime(2002, 6, 1, 0, 0)) | |
(4, None, 'Accessories', '2BE3BE36-D9A2-4EEE-B593-ED895D97C2A6', datetime.datetime(2002, 6, 1, 0, 0)) | |
(5, 1, 'Mountain Bikes', '2D364ADE-264A-433C-B092-4FCBF3804E01', datetime.datetime(2002, 6, 1, 0, 0)) | |
(6, 1, 'Road Bikes', '000310C0-BCC8-42C4-B0C3-45AE611AF06B', datetime.datetime(2002, 6, 1, 0, 0)) | |
(7, 1, 'Touring Bikes', '02C5061D-ECDC-4274-B5F1-E91D76BC3F37', datetime.datetime(2002, 6, 1, 0, 0)) | |
(8, 2, 'Handlebars', '3EF2C725-7135-4C85-9AE6-AE9A3BDD9283', datetime.datetime(2002, 6, 1, 0, 0)) | |
(9, 2, 'Bottom Brackets', 'A9E54089-8A1E-4CF5-8646-E3801F685934', datetime.datetime(2002, 6, 1, 0, 0)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Adventure Works Database on SQL Server 2019 | |
FROM mcr.microsoft.com/mssql/server:2019-CU5-ubuntu-18.04 | |
# Note: This isn't a secure password, and please don't use this for production. | |
ENV SA_PASSWORD=ThisIsAReallyCoolPassword123 | |
ENV ACCEPT_EULA=Y | |
# Setting the user | |
USER mssql |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Adventure Works Database on SQL Server 2019 | |
FROM mcr.microsoft.com/mssql/server:2019-CU5-ubuntu-18.04 | |
# Note: This isn't a secure password, and please don't use this for production. | |
ENV SA_PASSWORD=ThisIsAReallyCoolPassword123 | |
ENV ACCEPT_EULA=Y | |
# Change to root user to run wget and move the file | |
USER root |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CMD ["/opt/mssql/bin/sqlservr"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Launch SQL Server, confirm startup is complete, restore the database, then terminate SQL Server. | |
RUN ( /opt/mssql/bin/sqlservr & ) | grep -q "Service Broker manager has started" \ | |
&& /opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P ${SA_PASSWORD} -Q 'RESTORE DATABASE AdventureWorks2019 FROM DISK = "/var/opt/mssql/backup/AdventureWorks2019.bak" WITH MOVE "AdventureWorks2017" to "/var/opt/mssql/data/AdventureWorks2019.mdf", MOVE "AdventureWorks2017_Log" to "/var/opt/mssql/data/AdventureWorks2019_log.ldf", NOUNLOAD, STATS = 5' \ | |
&& pkill sqlservr |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
COPY AdventureWorks2019.bak /var/opt/mssql/backup/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Setting the user | |
USER mssql |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Note: This isn't a secure password, and please don't use this for production. | |
ENV SA_PASSWORD=ThisIsAReallyCoolPassword123 | |
ENV ACCEPT_EULA=Y |