In R, I have a SQL Server connection with this database:
From this answer I understand that these levels are catalogs (=databases), schemas, and tables
. The following code:
library(odbc)
library(DBI)
library(RSQlite)
library(dbi)
confull <- odbc::dbConnect(odbc(),
Driver = "SQL Server",
Server = "XXX")
odbcListObjects(confull, schema="schema")
Yields:
name type
1 DBAInfo catalog
2 InBluePrism catalog
3 master catalog
4 msdb catalog
5 tempdb catalog
Questions:
- How can I extract the full structure tree of this database, not just the
catalogs
? - How can I progammatically save (clone) this whole database (including all tables, schemas, and catalogs) into a local
SQLite
table?
For the first question I have tried the following:
> all_schemas <- DBI::dbGetQuery(confull, "SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA")
> all_schemas
SCHEMA_NAME
1 dbo
2 guest
3 INFORMATION_SCHEMA
4 sys
5 CCAutomation
6 XXXXXX\\xxxAdmin
7 XXXXXX\\z_swmon
8 NT AUTHORITY\\SYSTEM
9 XXXXXX\\z_Backup
10 db_owner
11 db_accessadmin
12 db_securityadmin
13 db_ddladmin
14 db_backupoperator
15 db_datareader
16 db_datawriter
17 db_denydatareader
18 db_denydatawriter
For the second question, I have tried:
- to generate scripts in SQL Server, but I get an error and moreover I would like to keep this programmatic.
- to just save all the tables given by
dbListTables(confull)
however, I then lose the information about the catalogs and schemas these tables belong to.
EDIT: the following link also contains useful information