diff --git a/samples/features/sql-big-data-cluster/data-virtualization/generic-odbc/README.md b/samples/features/sql-big-data-cluster/data-virtualization/generic-odbc/README.md new file mode 100644 index 00000000..7cffea0b --- /dev/null +++ b/samples/features/sql-big-data-cluster/data-virtualization/generic-odbc/README.md @@ -0,0 +1,41 @@ +# Data virtualization in SQL Server 2019 + +***Applies to:*** SQL Server 2019 on Windows only + +SQL Server 2019 introduces new ODBC connectors to data sources like SQL Server, Oracle, MongoDB and Teradata. The generic ODBC +connector can also be used to connect to other data sources like PostgreSQL, MySQL, IBM DB2 or any data source that provides +an ODBC driver. The ability to use the generic ODBC connector from SQL Server will be available only on Windows platform. + +The steps to use the generic ODBC connector are: + +1. Install the 64-bit ODBC Driver for the data source (ex: PostgreSQL, MySQL, IBM DB2, SAP HANA) on the SQL Server machine +1. Installation of the ODBC driver should be done at the system level +1. Use the Windows Control Panel ODBC applet (odbcad32) to determine the name of the ODBC Driver or refer to the ODBC Driver documentation + +## Query data in PostgreSQL from SQL Server + +In this example, you are going to create an external table in a SQL Server 2019 instance on Windows over the pg_tables view that sits on a PostgreSQL 11 server. The driver used to connect to the PostgreSQL server was the ***PostgreSQL ODBC Driver(UNICODE)*** driver. + +**Before you begin**, you need to have the PostgreSQL instance name and credentials + +### Instructions + +1. Connect to a SQL Server 2019 Windows instance and database. + +1. Modify the parameters in [postgresql/pg_tables.sql](postgresql/pg_tables.sql/). + +1. Execute the SQL [postgresql/pg_tables.sql](postgresql/pg_tables.sql/). + +## Query data in MySQL from SQL Server + +In this example, you are going to create an external table in a SQL Server instance on Windows over the pg_tables view that sits on a MySQL 8.0 server. The driver used to connect to the MySQL server was the ***MySQL 8.0 ODBC Driver Unicode Driver*** driver. + +**Before you begin**, you need to have the PostgreSQL instance name and credentials + +### Instructions + +1. Connect to a SQL Server 2019 Windows instance and database. + +1. Modify the parameters in [mysql/mysql_version.sql](mysql/mysql_version.sql/). + +1. Execute the SQL [mysql/mysql_version.sql](mysql/mysql_version.sql/). diff --git a/samples/features/sql-big-data-cluster/data-virtualization/generic-odbc/mysql/mysql_version.sql b/samples/features/sql-big-data-cluster/data-virtualization/generic-odbc/mysql/mysql_version.sql new file mode 100644 index 00000000..1267e9ff --- /dev/null +++ b/samples/features/sql-big-data-cluster/data-virtualization/generic-odbc/mysql/mysql_version.sql @@ -0,0 +1,66 @@ +-- Create database scoped credential to connect to MySQL server +-- Provide appropriate credentials to MySQL server in below statement. +-- If you are using SQL Server Management Studio then you can replace the parameters using +-- the Query menu, and "Specify Values for Template Parameters" option. +IF NOT EXISTS(SELECT * FROM sys.database_scoped_credentials WHERE name = 'MySQL80-user') + CREATE DATABASE SCOPED CREDENTIAL [MySQL80-user] + WITH IDENTITY = 'mssql-user' + , SECRET = 'sql19tw0mysql'; + +-- Create external data source that points to MySQL server +-- The tokens '%u' and '%p' is used to reference the credential information. +-- +IF NOT EXISTS(SELECT * FROM sys.external_data_sources WHERE name = 'MySQL80') + CREATE EXTERNAL DATA SOURCE MySQL80 + WITH (LOCATION = 'odbc://uc-win19-vm.redmond.corp.microsoft.com' + , CONNECTION_OPTIONS = 'Driver={MySQL 8.0 ODBC Driver Unicode Driver};User name=%u;Passwword=%p' + , CREDENTIAL = [MySQL80-user]); + +-- Create external table over inventory table on MySQL server +-- +IF NOT EXISTS(SELECT * FROM sys.external_tables WHERE name = 'mysql_version') + CREATE EXTERNAL TABLE mysql_version + ( + [sys_version] NVARCHAR(5) NOT NULL, + [mysql_version] NVARCHAR(6) NOT NULL + ) + WITH (LOCATION = 'sys.version', DATA_SOURCE = MySQL80); + +SELECT * FROM mysql_version; + +/* +IF NOT EXISTS(SELECT * FROM sys.external_tables WHERE name = 'mysql_tables') + CREATE EXTERNAL TABLE mysql_tables + ( + TABLE_CATALOG nvarchar(64), + TABLE_SCHEMA nvarchar(64), + TABLE_NAME nvarchar(64), + TABLE_TYPE nvarchar(64), + ENGINE nvarchar(64), + VERSION smallint, + ROW_FORMAT nvarchar(64), + TABLE_ROWS bigint, + AVG_ROW_LENGTH bigint, + DATA_LENGTH bigint, + MAX_DATA_LENGTH bigint, + INDEX_LENGTH bigint, + DATA_FREE bigint, + AUTO_INCREMENT bigint, + CREATE_TIME datetime2, + UPDATE_TIME datetime2, + CHECK_TIME datetime2, + TABLE_COLLATION nvarchar(64), + CHECKSUM bigint, + CREATE_OPTIONS nvarchar(256), + TABLE_COMMENT nvarchar(256) + ) + WITH (LOCATION = 'information_schema.tables', DATA_SOURCE = MySQL80); + +SELECT * FROM mysql_tables; +*/ +-- Cleanup +/* +DROP EXTERNAL TABLE mysql_tables +DROP EXTERNAL DATA SOURCE MySQL80 +DROP DATABASE SCOPED CREDENTIAL [MySQL80-user] +*/ diff --git a/samples/features/sql-big-data-cluster/data-virtualization/generic-odbc/postgresql/pg_tables.sql b/samples/features/sql-big-data-cluster/data-virtualization/generic-odbc/postgresql/pg_tables.sql new file mode 100644 index 00000000..75e7827f --- /dev/null +++ b/samples/features/sql-big-data-cluster/data-virtualization/generic-odbc/postgresql/pg_tables.sql @@ -0,0 +1,42 @@ +-- Create database scoped credential to connect to PostgreSQL server +-- Provide appropriate credentials to PostgreSQL server in below statement. +-- If you are using SQL Server Management Studio then you can replace the parameters using +-- the Query menu, and "Specify Values for Template Parameters" option. +IF NOT EXISTS(SELECT * FROM sys.database_scoped_credentials WHERE name = 'PostgreSQL11-user') + CREATE DATABASE SCOPED CREDENTIAL [PostgreSQL11-user] + WITH IDENTITY = '' + , SECRET = ''; + +-- Create external data source that points to PostgreSQL server +-- The tokens '%u' and '%p' is used to reference the credential information. +-- +IF NOT EXISTS(SELECT * FROM sys.external_data_sources WHERE name = 'PostgreSQL11') + CREATE EXTERNAL DATA SOURCE PostgreSQL11 + WITH (LOCATION = 'odbc://' + , CONNECTION_OPTIONS = 'Driver={PostgreSQL ODBC Driver(UNICODE)};User name=%u;Passwword=%p' + , CREDENTIAL = [PostgreSQL11-user]); + +-- Create external table over inventory table on PostgreSQL server +-- +IF NOT EXISTS(SELECT * FROM sys.external_tables WHERE name = 'pg_tables') + CREATE EXTERNAL TABLE pg_tables + ( + schemaname nvarchar(128) not null, + tablename nvarchar(128) not null, + tableowner nvarchar(128) not null, + tablespace nvarchar(128) not null, + hasindexes nvarchar(5) not null, + hasrules nvarchar(5) not null, + hastriggers nvarchar(5) not null, + rowsecurity nvarchar(5) not null + ) + WITH (LOCATION = 'postgres.pg_catalog.pg_tables', DATA_SOURCE = PostgreSQL11); + +SELECT * FROM pg_tables; + +-- Cleanup +/* +DROP EXTERNAL TABLE pg_tables +DROP EXTERNAL DATA SOURCE PostgreSQL11 +DROP DATABASE SCOPED CREDENTIAL [PostgreSQL11-user] +*/