循环得出数据库中所有的 DB_ID,DB_NAME

 1 --循环得出 数据库中所有的 DB_ID,DB_NAME
 2 CREATE TABLE #T
 3 (
 4   "DB_NAME()" int,
 5   "DB_ID" int,
 6   "DB_NAME" nvarchar(100) 
 7 )
 8 
 9 declare @n int=0
10 while(DB_NAME(@n)!='NULL')
11 BEGIN
12 insert  #T values(@n,DB_ID(DB_NAME(@n)),DB_NAME(@n))
13 set @n=@n+1
14 END
15 
16 SELECT * FROM #T
17 
18 DROP TABLE #T
19 
20 
21 --遍历 数据库中所有 DB_ID DB_NAME
22 declare @a int=0
23 while(DB_NAME(@n)!='NULL')
24 BEGIN
25 select @a as 'DB_NAME()',DB_NAME(@a) AS 'DBNAME()'
26 SET @a=@a+1
27 END
28 
29  
30 --判断是否为空
31 declare @a int=0
32 if(DB_NAME(6)!='NULL')
33 print CAST(1 AS NVARCHAR)+CHAR(9)+DB_NAME(6)
34 else
35 print 2
36 
37 declare @a int=0
38 if(DB_NAME(6)!='NULL')
39 begin
40 print CAST(1 AS NVARCHAR)+'制表符'+CHAR(9)+DB_NAME(6)
41 print CAST(1 AS NVARCHAR)+'换行'+CHAR(10)+DB_NAME(6)
42 print CAST(1 AS NVARCHAR)+'回车'+CHAR(13)+DB_NAME(6)
43 end
44 else
45 print 2

 

posted @ 2017-04-18 21:05  Devoloper_Jack  阅读(258)  评论(1编辑  收藏  举报