Importing Image Data into SQL Server 2005 Image Fields Using SQL Only
This article addresses the challenge of inserting an image into an Image type column using SQL alone in SQL Server 2005 and Management Studio. It also provides a method for verifying the successful insertion.
To begin, create a new table called "Employees" with the following schema:
CREATE TABLE Employees ( Id int, Name varchar(50) not null, Photo varbinary(max) not null )
Next, insert an image into the "Photo" column of the "Employees" table using the following SQL statement:
INSERT INTO Employees (Id, Name, Photo) SELECT 10, 'John', BulkColumn FROM Openrowset( Bulk 'C:\photo.bmp', Single_Blob) as EmployeePicture
Here, "photo.bmp" represents the actual image file that you want to insert, and "10" and "John" represent the Id and Name values for the employee record, respectively.
To verify that the image has been successfully inserted, you can use the following query:
SELECT * FROM Employees WHERE Id = 10
This query should return the entire employee record, including the Photo column. You can then view the image in the "Data" tab of Management Studio.
The above is the detailed content of How Can I Import Images into SQL Server 2005 Using Only SQL?. For more information, please follow other related articles on the PHP Chinese website!