T-SQL筆記50_實用的腳本part4_就某張table資料型別快速產生table varible宣告語句
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 DECLARE @collist NVARCHAR( max ) ,@ schema NVARCHAR( 128 ) ,@ table NVARCHAR( 128 ); SET @ schema = N 'dbo' ; SET @ table = N 'table name' ; SELECT @collist = STUFF(( SELECT N ', ' + CHAR ( 13 ) + col.name + N ' ' + typ.name + CASE WHEN typ.name IN ( N 'nchar' ,N 'char' ,N 'binary' ) THEN '(' + cast (col.max_length AS VARCHAR ) + ')' WHEN typ.name IN ( N 'nvarchar' ,N 'varchar' ,N 'varbinary' ) THEN CASE WHEN col.max_length = - 1 THEN N '(max)' ELSE CASE WHEN typ.name IN ( N 'varchar' ,N 'va