SQL加密数据
王燕杰
在网络上发送数据都会发生一些严重的安全问题,网络最大的担忧在于有人可以捕获数据,sqlserver支持采用证书来加密
1.创建证书
create master key encryption by
password = 'administrator123'
--用密码admini--
create certificate c1
encryption by password = 'administrator123'
with subject = 'c1 certificate',
start_date='03/08/2009',
expiry_date = '02/08/2020';
go
2.创建测试表,name字段为要加密的列,数据类型为varbinary
注意:加密的类型必须是varbinary,因为加密的数据是类型varbinary
create table testB(id int identity(1,1),name varbinary(5000))
3.使用加密函数向测试表中写入一条测试数据
insert into testB(name)
select encryptbycert(cert_id('c1'),'test')
4.利用下面的语句来提取加密数据
select * from testB
5.利用以下语句来解密数据
select id ,cast(decryptbycert(cert_id('c1'),name ,
N'administrator123')as varchar(20)) from testB
完成了
相关文档:
--------------------------------------------------------------------------
-- Author : 原著:不详 改编:htl258(Tony)
-- Subject: 完善SQL农历转换函数(显示中文格式,加入润月的显示)
-------------------------------------------------------------------------- ......
select * from ((select bill.id billId,bach.riskRate risk,bach.assureRate assure from AcptBillInfo bill,AcptBach bach where bill.acptBatchId=bach.id and bill.rgctId=? )abach left outer join AcptSignMoney sig on abach.billId = sig.billId) ......
我在将Excel的数据导入到SQL的时候老是出现下面的错误:
配置选项 'show advanced options' 已从 1 更改为 1。请运行 RECONFIGURE 语句进行安装。
配置选项 'Ad Hoc Distributed Queries' 已从 1 更改为 1。请运行 RECONFIGURE 语句进行安装。
消息 7399,级别 16,状态 1,第 1 行
链接服务器 "(null)" 的 OLE DB 访问 ......
这个逻辑关系乍看起来比较复杂,弄清楚了就好!
有两个表,
student(
id,
name,
primary key (id)
);
studentInfo(
id,
age,
address,
foreign key(id) references outTable(id) on delete cascade on update cascade
);
当我们删除student表的时候自然希望studentInfo里的相关信息也被删除,这就是外键起作用 ......
select a.ClassName,a.CourseName,sum(不及格) as 不及格,sum(差) as 差,sum(中等) as 中等,sum(好) as 好 ,sum(不及格)+sum(差)+sum(中等)+sum(好) as 班级总人数 from (select StudentID,ClassName,CourseName,1 as 不及格,0 as 差,0 as 中等,0 as 好 from StudentScore where ScoreRemark='fail' union all
select Stu ......