仅使用 SQL 将图片插入 SQL Server 2005 图像字段
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/416881/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 00:38:23 来源:igfitidea点击:
Insert Picture into SQL Server 2005 Image Field using only SQL
提问by Germstorm
Using SQL Server 2005 and Management Studio how do I insert a picture into an Image
type column of a table?
使用 SQL Server 2005 和 Management Studio 如何将图片插入Image
表的类型列?
Most importantly how do I verify if it is there?
最重要的是我如何验证它是否存在?
回答by Darin Dimitrov
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
回答by mathijsuitmegen
For updating a record:
更新记录:
UPDATE Employees SET [Photo] = (SELECT
MyImage.* from Openrowset(Bulk
'C:\photo.bmp', Single_Blob) MyImage)
where Id = 10
Notes:
笔记:
- Make sure to add the 'BULKADMIN' Role Permissions for the login you are using.
- Paths are not pointing to your computer when using SQL Server Management Studio. If you start SSMS on your local machine and connect to a SQL Server instance on server X, the file C:\photo.bmp will point to hard drive C: on server X, not your machine!
- 确保为您正在使用的登录添加“BULKADMIN”角色权限。
- 使用 SQL Server Management Studio 时,路径未指向您的计算机。如果您在本地计算机上启动 SSMS 并连接到服务器 X 上的 SQL Server 实例,则文件 C:\photo.bmp 将指向服务器 X 上的硬盘驱动器 C:,而不是您的计算机!
回答by prasanna.yelsangikar
Create Table:
创建表:
Create Table EmployeeProfile (
EmpId int,
EmpName varchar(50) not null,
EmpPhoto varbinary(max) not null )
Go
Insert statement:
插入语句:
Insert EmployeeProfile
(EmpId, EmpName, EmpPhoto)
Select 1001, 'Vadivel', BulkColumn
from Openrowset( Bulk 'C:\Image1.jpg', Single_Blob) as EmployeePicture
This Sql Query Working Fine.
这个 Sql 查询工作正常。