I have created a table in Azure SQL Data Warehouse as below:
CREATE TABLE dbo.test_lob_type
(
id VARCHAR(80) NOT NULL,
mime_type VARCHAR(80) NOT NULL,
binary_lob VARBINARY(MAX) NULL
)
WITH
(
DISTRIBUTION = HASH ( id ),
CLUSTERED INDEX ( id ASC )
);
I want to insert a BLOB object into this table. I tried to achieve this using the OPENROWSET command as pointed in the link How to insert a blob into a database using sql server management studio
But unfortunately this command does not work with Azure SQL DW. Can anyone provide any input on how to insert any BLOB object into a SQL DW table from the command line?
bcp is supported for this scenario. Here is a simple example using SQL Authentication and char format:
REM Example using SQL Authentication and character file
bcp dbo.test_lob_type in test_lob_type.bcp -S yourDWServer.database.windows.net -d yourDWName -U yourLogin -P yourPassword -c
If your file only contains the blob, consider loading to a staging table before inserting into the main table.
Related
We have a scenario where the source csv files are isolated by Customer i.e., each Customer will have a Container in the Azure Storage.
When creating External Table in SQL Synapse, is it possible to pass the Container name as parameter that way there are not multiple External Data Tables in SQL Synapse DB?
CREATE EXTERNAL DATA SOURCE AzureBlobStorage with (
TYPE = HADOOP,
LOCATION ='wasbs://<**container100**>#<accountname>.blob.core.windows.net',
CREDENTIAL = AzureStorageCredential
);
CREATE EXTERNAL TABLE [dbo].[res1_Data] (
[ID] INT,
[UniqueId] VARCHAR(50),
[Status] VARCHAR(50) NULL,
[JoinedDate] DATE
)
WITH (LOCATION='<**container2**>/<folder>/<file>.csv',
DATA_SOURCE = AzureBlobStorage,
FILE_FORMAT = CEFormat
);
Unfortunately you can't use variables within DDL commands. However, you can build dynamic statements and then execute with sp_executesql to do this.
More information here.
Is there any option to query the Azure SQL Data warehouse (Cloud) from the Azure SQL Server database (Cloud)?
We have a central warehouse hosted in cloud with all the domains needed for the Application. It would be great if we can use those tables as external tables using the approach described at https://azure.microsoft.com/en-us/blog/querying-remote-databases-in-azure-sql-db.
Querying Data Warehouse from SQL DB is currently unsupported.
You can access Azure SQL Data Warehouse from Azure SQL using external tables
Here's the article: https://learn.microsoft.com/en-us/sql/t-sql/statements/create-external-table-transact-sql
Example:
CREATE MASTER KEY
CREATE DATABASE SCOPED CREDENTIAL dwcredential WITH IDENTITY = '<username>',
SECRET = '<password>';
CREATE EXTERNAL DATA SOURCE sqldw WITH
(
TYPE = RDBMS,
LOCATION = N'<dwserver>.database.windows.net',
DATABASE_NAME = N'<dwdatabasename>',
CREDENTIAL = dwcredential
)
GO
CREATE EXTERNAL TABLE [<azuresqltablename>](
[col1] [int] NOT NULL,
[col2] [int] NOT NULL
)
WITH
(
DATA_SOURCE = sqldw,
SCHEMA_NAME = 'dbo', --schema name of remote table
OBJECT_NAME = '<dwtablename>' --table name of remote table
);
Is it possible to execute a SQL Select statement on a CSV file on a Sybase Database?
Update DBA.user_data
set user_data.date_Sent = '12/16/2015'
where user_data.caseid in (select caseid
from DBA.cases
where cases.caseid=user_data.caseid
And cases.caseid in (select * FROM 'C:\\example\\test.csv' WITH (FIELDTERMINATOR = ',',ROWTERMINATOR = '\n')));
Assuming you are using Sybase ASE, you can access flat files using the Component Integration Services (CIS).
I suggest you check out the Component Integration Services User Guide, which is part of the SAP/Sybase documentation.
Check out the section on File system access: File Access
You will create a proxy (or existing) table, using the file information in the definition.
create proxy_table <table_name>
external file at " pathname" [column delimiter “<string>”]
OR
create existing table fname (
column1 int null,
column2 datetime null,
column3 varchar(1024) null
etc. etc.
) external file at "pathname" [column delimiter “<string>”]
Only the select, insert, and truncate table statements are supported
for file access. update and delete result in errors if the file proxy
is the target of these commands.
Documentation: create proxy_table
I have some .sql-files with creates tables (MS SQL Database):
table_1.sql:
IF OBJECT_ID (N'my_schema.table1', N'U') IS NOT NULL
DROP TABLE my_schema.table1;
CREATE TABLE my_schema.table1(
id int IDENTITY PRIMARY KEY,
nameTable1 varchar(255) NOT NULL UNIQUE
);
and table_2.sql:
IF OBJECT_ID (N'my_schema.table2', N'U') IS NOT NULL
DROP TABLE my_schema.table2;
CREATE TABLE my_schema.table2(
id int IDENTITY PRIMARY KEY,
nameTable2 varchar(255) NOT NULL UNIQUE
);
so, and I want run these two .sql-files in third file: run_all_tables.sql,
How can to run table_1.sql and table_2.sql via run_all_tables.sql, I think it should be similar:
run_all_tables.sql:
BEGIN;
\i table_1.sql
\i table_2.sql
COMMIT;
What must be in run_all_tables.sql for to run table_1.sql and table_2.sql? If you have MS SQL Database (Microsoft SQL Server)
You use SQLCMD to execute .sql files sequentially. Putting the files in a single folder called Scripts, you would create the run_all_tables.sql file like so:
PRINT 'CREATING TABLES'
:r c:\Scripts\table_1.sql
:r c:\Scripts\table_2.sql
PRINT 'TABLE CREATION IS COMPLETE'
After creating that, you call it from command line, connecting to the database server.
SQLCMD -S Servername\Instancename -d DatabaseName -i c:\Scripts\run_all_tables.sql
I have a stored procedure that accept a UDTT(User Define Table Type). I'd like to test the performance using data input from csv files. Since the store procedure handles foreign key relationship, I will not use SQL build-in bulk inserts. How to do this in SQL management studio?
Here is the steps that I found works:
BCP the data from csv file to a temp table.
bcp TempDb.dbo.CsvTest in "C:\test.csv" -T -c -t ,
Use the temp table to populate the UDTT
INSERT INTO #args
SELECT col1, col2 FROM TempDb.dbo.CsvTest
EXEC #return_value = [dbo].[myProcedure] #inputs = #args
Not sure if there is a way to skip the temp table.