SQLServer中获取当前数据库名称

(1):Select Name From Master..SysDataBases Where DbId=(Select Dbid From Master..SysProcesses Where Spid = @@spid)

(2):--NoteMessage 为数据库名称
if db_id('NoteMessage')=(Select Dbid From Master..SysProcesses Where Spid = @@spid)
print 'OK'

你可能感兴趣的:(sqlserver)