T-SQL转义引号字符 [英] T-SQL escape quote character

查看:114
本文介绍了T-SQL转义引号字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

注意:这可能是重复的,但我找不到工作答案。

NOTE: It's probably a duplicate but I can't find working answer.

以下是我想要的,注意一个 '中的值。如何解决这个问题?

Following is what i'm trying todo, notice a ' in the value. How do I fix this?

INSERT INTO [pugraider]。[dbo]。[Realms]([Name])VALUES('Aman' Thul')

我使用MS SQL Server Management Studio 2008。

I use MS SQL Server Management Studio 2008.

编辑:我正在编写一个脚本来填充查找表(ID < - > Name)。

I'm writing a script to populate a lookup table (ID<->Name).

推荐答案

这将工作:

INSERT INTO [pugraider].[dbo].[Realms]([Name]) VALUES('Aman''Thul')

通常在T-SQL中具有这样的硬编码值的唯一原因是在DB构造代码中,例如初始化查找表。

Ordinarily the only reason to have such hardcoded values in T-SQL is in DB construction code such as initialising look up tables.

否则,此代码可能是字符串连接从一些输入源构建一些T-SQL的结果。如果是这样的话,它值得寻找方法来避免它,因为它可以打开你的应用程序进行SQL注入攻击。

Otherwise this code might be a result of string concatenation to build up some T-SQL from some input source. If that is the case its worth finding ways to avoid it since it can open your application to SQL injection attacks.

这篇关于T-SQL转义引号字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆