我通过将字符字母向下移动一个由键给出的槽数来加密表名和列名。 例如,当key = 3时,“A”变为“D”,“z”变为“c”,“1”变为“4”。
以下是我加载数据的代码:
USE testdata
GO
CREATE testtable
(TREATMENT CHAR(20),
PRICE INT)
GO
BULK INSERT testtable
FROM 'c:\testdata.txt'
WITH
(
FIELDTERMINATOR = ',',
ROWTERMINATOR = '\n'
)
GO
SELECT *
FROM testtable
GO
我怎么能这样做?我需要动态sql吗?
谢谢!
答案 0 :(得分:0)
我已经编写了一个修改字符串的过程,但不确定如何在列名
上使用它create procedure encrypt
@ptext as varchar(500)
as
begin
set nocount on
declare @key as tinyint = 3
declare @etext as varchar(500) = ‘ ’
declare @pc as varchar(1)
declare @i as smallint = 1
declare @n as smallint
set @n = len(@ptext)
while @i <= @n
begin
set @pc = substring (@ptext, @i, 1)
if ascii(@pc) between 48 and 57
begin
if ascii(@pc) + @key < 58
set @pc = char((ascii(@pc) + @key))
else
set @pc = char((ascii(@pc) + @key)-10)
end
else if ascii(@pc) between 65 and 90
begin
if ascii(@pc) + @key < 91
set @pc = char((ascii(@pc) + @key))
else
set @pc = char((ascii(@pc) + @key)-26)
end
if ascii(@pc) between 97 and 122
begin
if ascii(@pc) + @key < 123
set @pc = char((ascii(@pc) + @key))
else
set @pc = char((ascii(@pc) + @key)-26)
end
set @etext = @etext + @pc
set @i = @i + 1
end
select @etext
end