为什么' TestDatabase2'还匹配' TestDatabase'?同样,' D2'也匹配' D'。
exec sp_executesql N'SELECT TOP 1
sdb.name AS DbName,
bus.backup_start_date AS LastBackUpTime,
bus.type AS Type
FROM
sys.sysdatabases sdb
LEFT OUTER JOIN
msdb.dbo.backupset bus
ON
bus.database_name = sdb.NAME
AND
bus.type = @backupType
WHERE
sdb.name = @dbname
ORDER BY
LastBackUpTime DESC',N'@dbName nvarchar(12),@backupType nvarchar(1)',@dbName=N'TestDatabase',@backupType=N'D'
答案 0 :(得分:6)
数据库名称的参数是NVARCHAR(12)
。
猜猜TestDatabase
有多少个字符;)
SELECT CAST('TestDatabase' as NVARCHAR(12)), CAST('TestDatabase12314' as NVARCHAR(12))
您应该将其设为NVARCHAR(128)
或SYSNAME
,这是msdb.dbo.backupset.database_name
和sys.databases.name
列的长度。