Table of contents
TOC
Collapse the table of content
Expand the table of content

rxExecuteSQLDDL

j-martens|Last Updated: 12/15/2016
|
1 Contributor

Executes a DDL command to define, manipulate, or control SQL data, but not return data.

Usage

rxExecuteSQLDDL(src, ...)

Arguments

src: An RxOdbcData data source object

Other additional arguments are typically of the type sSQLString=, after which you would supply a string containing a well-formed T-SQL DDL statement.

For example, you could add create a table, add a column to a table, or truncate a table before inserting new data.

Return Value

Returns NULL. If you need to verify that the DDL statement was executed successfully, you can use a try-catch statement with an ODBC call to check for table names, columns, etc.

Example

The following example demonstrates how to load data from a text file into a new database table.

# Define the database where DDL statements will be executed

conString <- "Driver=SQL Server;Server=localhost;Database=RTest;Uid=tester;pwd=pwd;"
outOdbcDS <- RxOdbcData(table = "NewData", connectionString = conString, useFastRead=TRUE)         

# Open the ODBC connection and execute the DDL statement
rxOpen(outOdbcDS, "w")                       
rxExecuteSQLDDL(outOdbcDS, sSQLString = paste("CREATE TABLE [NewData]([Col1] [int] NULL, [Col2] [char](25) NULL, [Col3] [float] NULL);", sep=""))

# Get the new data from a text file
inTextData <- RxTextData(file = file.path("C:\\Temp"), "newdata.txt"), stringsAsFactors = TRUE, useFastRead = TRUE)
outOdbcDS <- RxOdbcData(table = "NewData",  connectionString = conString, useFastRead=TRUE)

# Move the data from one data source to another
rxDataStep(inData = inTextData, outFile = outOdbcDS)

See Also

Comparison of rx Functions and CRAN R Functions

ScaleR Functions for Working with SQL Server Data

© 2017 Microsoft