我正在考虑一种情况,我有两个高密度的列,但这些列不是独立的。
这是我为测试目的而创建的表的定义。
CREATE TABLE [dbo].[StatsTest](
[col1] [int] NOT NULL, --can take values 1 and 2 only
[col2] [int] NOT NULL, --can take integer values from 1 to 4 only
[col3] [int] NOT NULL, --integer. it has not relevance just to ensure that each row is different
[col4] AS ((10)*[col1]+[col2]) --a computed column ensuring that if two rows have different values in col1 or col2 have different values in col4
) ON [PRIMARY]
Run Code Online (Sandbox Code Playgroud)
实验数据如下
col1 col2 col3 col4
1 …
Run Code Online (Sandbox Code Playgroud) 如果无法在函数中使用非确定性函数,那么在 SQL Server 中创建密码生成器用户定义函数函数的最佳方法是什么?
我想创建一个函数,该函数使用给定字符串中的字符返回随机生成的 varchar(10),如下所示:“1234567890QWERTYUIOPASDFGHJKLZXCVBNM”
我有自己的想法,但不是很自然的解决方案。
该功能背后的想法是,如果有人需要重置密码,我可以执行以下操作:
UPDATE Users SET Password = dbo.GeneratePassword() WHERE UserID = @UserID
Run Code Online (Sandbox Code Playgroud)
一个函数比单独的预分配密码表更容易部署和重用。