Inserting A mdi file in SQL Server - sql-server

I am trying to insert a mdi file in a SQL Server 2008 table.
Do you know how can I do this?
My table has the following structure
Create table employées
(
Id_employee int,
Mdi_employee image
)

Convert your MDI file into Byte format and then use normal query to insert that image.
For More information : C# Resize jpg image, convert to byte and save into database using varbinary

Related

Migrating from SQL Server to Hive Table using flat file

I am migrating my data from SQL Server to Hive using following steps but there is data issue with the resulting table. I tried various options including checking datatype, Using csvSerde but not able to get data aligned properly in respective columns. I followed following steps:
Export SQL Server data to flat file with fields separated by comma.
Create external table in Hive as given below and load data.
CREATE EXTERNAL TABLE IF NOT EXISTS myschema.mytable (
r_date timestamp
, v_nbr varchar(12)
, d_account int
, d_amount decimal(19,4)
, a_account varchar(14)
)
row format delimited
fields terminated by ','
stored as textfile;
LOAD DATA INPATH 'gs://mybucket/myschema.db/mytable/mytable.txt' OVERWRITE INTO TABLE myschema.mytable;
There is issue with data with all combination I could try.
I also tried OpenCSVSerde but the result was worse than simple text file. I also tried by changing delimiter to semicolon but no luck.
row format serde 'org.apache.hadoop.hive.serde2.OpenCSVSerde'
with serdeproperties ( "separatorChar" = ",") stored as textfile
location 'gs://mybucket/myschema.db/mytable/';
Can you please suggest some robust approach so that I don't have to deal with data issue.
Note: Currently I don't have option of connecting my SQL Server table with Sqoop.

How to insert binary file into a binary SQL column?

I have a SQL Server 2008 database with a table containing an image column.
Any idea how to write query to insert bin file to the image field?
Thank you in advance!
Totally agree with marc_s.
But your query will be something like this.
INSERT yourtable(ImageColumn)
SELECT image FROM
OPENROWSET(BULK, 'filename.png', SINGLE_BLOB) AS blobtable(image)

How to script VARBINARY to copy it from one DB to another using a script?

I need to generate an SQL insert script to copy data from one SQL Server to another.
So with .net, I'm reading the data a given SQL Server table and write this to a new text file which can then be executed in order to insert this data on other databases.
One of the columns is a VARBINARY(MAX).
How should and can I transform the obtained byte[] into text for the script so that it can still be inserted on the other databases?
SSMS shows this data as hex string. Is this the format to use?
I can get this same format with the following
BitConverter.ToString(<MyByteArray>).Replace("-", "")
But how can this be inserted again?
I tried
CONVERT(VARBINARY(MAX), "0xMyHexString")
This does an insert, but the value is not the same as in the source table.
It turned out you can just directly insert the hex string, no need to convert anything:
INSERT TableName (VarBinColumnName)
VALUES (0xMyHexString)
Just don't ask why I didn't test this directly...
There are two questions on SO that may help:
What is the fastest way to get varbinary data from SQL Server into a C# Byte array?
and
How Do I Insert A Byte[] Into an SQL Server VARBINARY column?

How can I insert binary file data into a binary SQL field using a simple insert statement?

I have a SQL Server 2000 with a table containing an image column.
How do I insert the binary data of a file into that column by specifying the path of the file?
CREATE TABLE Files
(
FileId int,
FileData image
)
I believe this would be somewhere close.
INSERT INTO Files
(FileId, FileData)
SELECT 1, * FROM OPENROWSET(BULK N'C:\Image.jpg', SINGLE_BLOB) rs
Something to note, the above runs in SQL Server 2005 and SQL Server 2008 with the data type as varbinary(max). It was not tested with image as data type.
If you mean using a literal, you simply have to create a binary string:
insert into Files (FileId, FileData) values (1, 0x010203040506)
And you will have a record with a six byte value for the FileData field.
You indicate in the comments that you want to just specify the file name, which you can't do with SQL Server 2000 (or any other version that I am aware of).
You would need a CLR stored procedure to do this in SQL Server 2005/2008 or an extended stored procedure (but I'd avoid that at all costs unless you have to) which takes the filename and then inserts the data (or returns the byte string, but that can possibly be quite long).
In regards to the question of only being able to get data from a SP/query, I would say the answer is yes, because if you give SQL Server the ability to read files from the file system, what do you do when you aren't connected through Windows Authentication, what user is used to determine the rights? If you are running the service as an admin (God forbid) then you can have an elevation of rights which shouldn't be allowed.

Translating SQL for use with Oracle

I have 2 Oracle questions
How do I translate this SQL Server statement to work on Oracle?
Create table MyCount(Line int identity(1,1))
What is the equivalent of SQL Servers Image type for storing pictures in an Orace database?
You don't need to use triggers for this if you manage the inserts:
CREATE SEQUENCE seq;
CREATE TABLE mycount
(
line NUMBER(10,0)
);
Then, to insert a value:
INSERT INTO mycount(line) VALUES (seq.nextval);
For images, you can use BLOBs to store any binary data or BFILE to manage more or less as a BLOB but the data is stored on file system, for instance a jpg file.
References:
Create Sequence reference.
Create table reference.
Oracle® Database Application Developer's Guide - Large Objects.
1: You'll have to create a sequence and a trigger
CREATE SEQUENCE MyCountIdSeq;
CREATE TABLE MyCount (
Line INTEGER NOT NULL,
...
);
CREATE TRIGGER MyCountInsTrg BEFORE INSERT ON MyCount FOR EACH ROW AS
BEGIN
SELECT MyCountIdSeq.NEXTVAL INTO :new.Line
END;
/
2: BLOB.
Our tools can answer these questions for you. I'm talking about Oracle SQL Developer.
First - it has a Create Table wizard - and 12/18c Database supports native implementation of Identity columns.
And your new table DDL
CREATE TABLE MYCOUNT
(
LINE INT GENERATED ALWAYS AS IDENTITY NOT NULL
);
Also, we have a Translator - it can take SQL Server bits and turn them into equivalent Oracle bits. There's a full-blown migration wizard which will capture and convert your entire data model.
But for one-offs, you can use your Scratchpad. It's available under the Tools, Migrations menu.
Here it is taking your code and giving you something that would work in any Oracle Database.
Definitely use the identity feature in 12/18c if you're on that version of Oracle. Fewer db objects to maintain.

Resources