(1) Export to Parquet file:
import pandas as pd
from sqlalchemy import create_engine
#[1]: Connect to SQL Server using SQLAlchemy
engine = create_engine('mssql+pyodbc://goadmin:topsecret@localhost\ENGSQL/demodb?driver=SQL+Server')
#[2]: Execute SQL query and fetch data
sql_query = "SELECT * FROM sysdatabases"
data = pd.read_sql(sql_query, engine)
#[3]: Write data to Parquet file
parquet_file_path = "sysdatabases.parquet"
data.to_parquet(parquet_file_path)
print("Parquet file generated successfully.")
[2] Read from Parquet file:
import pyarrow.parquet as pq
Specify the path to your Parquet file
parquet_file_path = "sysdatabases.parquet"
Read the Parquet file
table = pq.read_table(parquet_file_path)
Convert the table to a pandas DataFrame
df = table.to_pandas()
Print the DataFrame
print(df)
#parquet
#parquetfile
#sqlserver
#sqlservermanagementstudio
#sqlservertutorial
Watch video How to export Parquet file from SQL Server? online without registration, duration hours minute second in high quality. This video was added by user Coding Studio 26 March 2024, don't forget to share it with your friends and acquaintances, it has been viewed on our site 1,610 once and liked it 5 people.