수색…


RODBC를 통해 Excel 파일에 연결

RODBC 는 R과 모든 대상 RDMS간에 호환 가능한 아키텍처가있는 Windows 컴퓨터로 제한되지만 Excel 데이터베이스의 주요 기능 중 하나는 SQL 데이터베이스 인 것처럼 Excel 파일을 사용하는 것입니다.

require(RODBC)
con = odbcConnectExcel("myfile.xlsx") # open a connection to the Excel file
sqlTables(con)$TABLE_NAME # show all sheets
df = sqlFetch(con, "Sheet1") # read a sheet
df = sqlQuery(con, "select * from [Sheet1 $]") # read a sheet (alternative SQL syntax)
close(con) # close the connection to the file

SQL Server 관리 데이터베이스 연결을 사용하여 개별 테이블 가져 오기

RODBC의 또 다른 용도는 SQL Server 관리 데이터베이스에 연결하는 것입니다. 여기서 'Driver'즉, SQL Server, 데이터베이스 이름 "Atilla"를 지정하고 sqlQuery 를 사용하여 전체 테이블 또는 그 일부를 추출해야합니다.

library(RODBC) 
cn  <- odbcDriverConnect(connection="Driver={SQL Server};server=localhost;database=Atilla;trusted_connection=yes;")
tbl <- sqlQuery(cn, 'select top 10 * from table_1')

관계형 데이터베이스에 연결

library(RODBC)
con <- odbcDriverConnect("driver={Sql Server};server=servername;trusted connection=true")
dat <- sqlQuery(con, "select * from table");
close(con)

이렇게하면 SQL Server 인스턴스에 연결됩니다. 연결 문자열의 모양에 대한 자세한 내용은 connectionstrings.com을 방문하십시오.

또한 데이터베이스가 지정되지 않았으므로이 databasename.schema.objectname과 같이 쿼리하려는 개체를 완전히 한정해야합니다.



Modified text is an extract of the original Stack Overflow Documentation
아래 라이선스 CC BY-SA 3.0
와 제휴하지 않음 Stack Overflow