O'Reilly logo

R Data Analysis Cookbook - Second Edition by Kuntal Ganguly

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Using RODBC

In this method, we execute the following command:

> con <- odbcConnect("cust_dsn", uid="user", pwd="pwd") 

The con variable now has a connection to the database associated with the DSN. All subsequent database calls use this connection object. When all database operations are done, we close the connection.

Although we will typically not create tables or insert data from R, we have shown the code for this just for illustration. The sqlSave function saves the data in the R data object to the specified table. We used append=FALSE because the table does not already exist, and, hence, we will want R to create the table first and then insert the data. If the table already exists, you can use append=TRUE.

The sqlQuery function executes ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required