如何使用 SQLServer2005和 ManagementStudio 将图片插入到表的 Image类型列中?
Image
最重要的是,我如何验证它是否存在?
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
创建表格:
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 查询工作正常。
用于更新记录:
UPDATE Employees SET [Photo] = (SELECT MyImage.* from Openrowset(Bulk 'C:\photo.bmp', Single_Blob) MyImage) where Id = 10
备注:
我实现了在数据库中插入多个图像的目标
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')