Learn R Programming

nolock (version 1.1.0)

nolock: 'Append WITH (NOLOCK) to SQL Queries'

Description

Automatically appends 'WITH (nolock)' to all tables in 'SQL' queries using a utility function. This facilitates reading from databases in scenarios where non-blocking reads are preferable, such as in high-transaction environments.

Usage

nolock(query = NULL)

Value

Returns the processed 'SQL' query as a character vector with 'WITH (nolock)' added for each table in the query.

Arguments

query

Character vector. 'SQL' query to be processed. If NULL, a temporary 'SQL' text document is opened for user input.

Examples

Run this code

example_SQL <- "

WITH CTE AS (SELECT C.TABLE_NAME,
                    C.COLUMN_NAME,
                    T.TABLE_TYPE
             FROM INFORMATION_SCHEMA.COLUMNS AS C
                      JOIN INFORMATION_SCHEMA.TABLES T ON C.TABLE_NAME = T.TABLE_NAME)

SELECT *
FROM CTE;"

nolock(query = example_SQL)

if (FALSE) {
nolock()
}

Run the code above in your browser using DataLab