Connect insert and retreive data from SQL Server db on AWS RDS Jupyter notebook

Опубликовано: 01 Январь 2019
на канале: Learn 2 Excel
6,282
42

Published on January 01, 2019:


In this video, we will learn:
1. Connect to SQL Server database on aws
2. Create a table in SQL Server database
3. Insert data to the created table

In the previous video, we learnt:
1. Create table in mysql database
2. Insert data to the created table
3. Fetch data intserted to the table

Previous Video:
   • Connect to MYSQL RDS on AWS using Jup...  


Additional Reading material:
NA

#Script used
#Install the pymysql package
!conda install -y -q pymssql
#importing the package
#cell 1
import pymssql
#Creating a connection
#cell 2
connection={
'host': 'testdb.c7yyjciim0sy.ap-southeast-2.rds.amazonaws.com',
'username': 'admin',
'password': 'Welcome123',
'db': 'Pythondemo'
}
#creating a connection
con=pymssql.connect(connection['host'],connection['username'],connection['password'])
#Closing the connection
con.close()

#Opening the connection
#cell 3
con=pymssql.connect(connection['host'],connection['username'],connection['password'],connection['db'])

#Creating a cursor
#cell 4
cursor=con.cursor()
#Creating a table
#cell 5
create_table="""
create table salespeople (
salesPersonId int,
salesPersonName varchar(20)
)

"""
#Executing the create table
#cell 6
cursor.execute(create_table)
#cell 7
con.commit()

#Inserting the data
#cell 8
insert_statement="""
Insert into salespeople
(salesPersonId,salesPersonName)
values
(1,'Daffy Duck')

"""
#Executing the insert
#cell 9
cursor.execute(insert_statement)
#Hit con.commit to get things into AWS
#cell 10
con.commit()

#cell 11
select_statement="""
Select * from salespeople

"""
#cell 12
cursor.execute(select_statement)
#get the resultset
#cell 13
result=cursor.fetchall()
#print the resultset
#cell 14
for row in result:
print(row)
con.close()




SUBSCRIBE to learn more about Power BI,Power Query, Power Pivot, Excel,SQL Server and Python!!
   / @learnexcelrelentless  



Our Playists:
SQL Playlist :https://goo.gl/PS5Ep6
DAX PlayList : https://goo.gl/S4W41D
Power BI PlayList: https://goo.gl/dXxvnB
Power Query Playlist: https://goo.gl/5QS7P4
Getting Started with Power BI:https://goo.gl/GHakLZ
Getting Started with Python: https://goo.gl/n24P3w
Data Science With Python:https://goo.gl/PeYCR5


ABOUT DAGDOO:
Website:
Home Page: http://www.dagdoo.org/
Power BI Tutorials: http://www.dagdoo.org/excel-learning/...


Questions? Comments and SUGESTIONS? You will find me here:

Twitter: @dagdooe

Category: Science & Technology
License: Standard YouTube License