使用SQL Server 2005和Management Studio,如何将图片插入Image
表的类型列中?
最重要的是,我如何验证它是否在那里?
Answers:
CREATE TABLE Employees
(
Id int,
Name varchar(50) not null,
Photo varbinary(max) not null
)
INSERT INTO Employees (Id, Name, Photo)
SELECT 10, 'John', BulkColumn
FROM Openrowset( Bulk 'C:\photo.bmp', Single_Blob) as EmployeePicture
要更新记录:
UPDATE Employees SET [Photo] = (SELECT
MyImage.* from Openrowset(Bulk
'C:\photo.bmp', Single_Blob) MyImage)
where Id = 10
笔记:
创建表:
Create Table EmployeeProfile (
EmpId int,
EmpName varchar(50) not null,
EmpPhoto varbinary(max) not null )
Go
插入语句:
Insert EmployeeProfile
(EmpId, EmpName, EmpPhoto)
Select 1001, 'Vadivel', BulkColumn
from Openrowset( Bulk 'C:\Image1.jpg', Single_Blob) as EmployeePicture
此Sql查询工作正常。
我实现了将多个图像插入数据库的目标
INSERT INTO [dbo].[User]
([Name]
,[Image1]
,[Age]
,[Image2]
,[GroupId]
,[GroupName])
VALUES
('Umar'
, (SELECT BulkColumn
FROM Openrowset( Bulk 'path-to-file.jpg', Single_Blob) as Image1)
,26
,(SELECT BulkColumn
FROM Openrowset( Bulk 'path-to-file.jpg', Single_Blob) as Image2)
,'Group123'
,'GroupABC')