10) Fetch an entire table from an SQL Server Database

This Blog entry is from the Loading and Shaping section in Learn R.

It suffices, for the purpose of this procedure, that there is a table in the SQL Server database titled AAPL containing the same information as the AAPL.csv and AAPL.txt files loaded in previous Blog entries:

1.png

Offloading data mining and wrangling to SQL Server should ideally be offloaded to stored procedures rather than table selects or SQL.  For the purposes of this procedure, select the contents of the table to a Data Frame by typing:

AAPL <- sqlQuery(Connection,"select * from AAPL")
2.png

Run the line of script to console to execute the SQL statement "select * from AAPL" via the connect established in the previous Blog entry:

3.png

The absence of any errors indicates that the SQL Query ran successfully, while an execution of the View() function against the data frame can further offer validation:

View(AAPL)
4.png

Run the line of script to console to expand the AAPL data frame into a table in the script section of RStudio:

5.png