久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

如何使用括號(hào)和所有內(nèi)容獲取 SQL Server 列定義?

How can I get SQL Server column definition with parentheses and everything?(如何使用括號(hào)和所有內(nèi)容獲取 SQL Server 列定義?)
本文介紹了如何使用括號(hào)和所有內(nèi)容獲取 SQL Server 列定義?的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

限時(shí)送ChatGPT賬號(hào)..

我需要一種聰明的方法來以可在 CREATE TABLE 語句中使用的方式從 INFORMATION_SCHEMA.COLUMNS 中獲取數(shù)據(jù)類型.問題是需要理解的額外"字段,例如 NUMERIC_PRECISION 和 NUMERIC_SCALE.

顯然,我可以忽略 INTEGER 的列(精度為 10,小數(shù)位數(shù)為 0),但還有其他類型我會(huì)感興趣,例如 NUMERIC.因此,無需編寫大量代碼來解析表,是否有任何關(guān)于如何從列定義中獲取某種字段速記的想法?

我希望能夠得到類似的東西:內(nèi)部,約會(huì)時(shí)間,錢,數(shù)字**(10,2)**

解決方案

這是 GalacticCowboy 的回答的更新(抄襲!)

a> 修復(fù)一些問題并更新所有(我認(rèn)為)SQL Server 2008R2 數(shù)據(jù)類型:

選擇數(shù)據(jù)類型+案件當(dāng) data_type 像 '%text' 或 data_type in ('image', 'sql_variant' ,'xml')然后 ''當(dāng) data_type in ('float')然后 '(' + cast(coalesce(numeric_precision, 18) as varchar(11)) + ')'當(dāng) data_type in ('datetime2', 'datetimeoffset', 'time')然后 '(' + cast(coalesce(datetime_precision, 7) as varchar(11)) + ')'當(dāng) data_type in ('decimal', 'numeric')然后 '(' + cast(coalesce(numeric_precision, 18) as varchar(11)) + ',' + cast(coalesce(numeric_scale, 0) as varchar(11)) + ')'當(dāng) (data_type like '%binary' 或 data_type like '%char') 和 character_maximum_length = -1然后'(最大)'當(dāng) character_maximum_length 不為空時(shí)然后 '(' + cast(character_maximum_length as varchar(11)) + ')'別的 ''以 CONDENSED_TYPE 結(jié)尾, *來自 information_schema.columns按 table_schema、table_name、ordinal_position 排序

I need a smart way to get the data types out of INFORMATION_SCHEMA.COLUMNS in a way that could be used in a CREATE TABLE statement. The problem is the 'extra' fields that need to be understood, such as NUMERIC_PRECISION and NUMERIC_SCALE.

Obviously, I can ignore the columns for INTEGER (precision of 10 and scale of 0), but there are other types I would be interested in, such as NUMERIC. So without writing lots of code to parse the table, any ideas on how to get a sort of field shorthand out of the column definition?

I would like to be able to get something like : int, datetime, money, numeric**(10,2)**

解決方案

Here is an update (ripoff!) of GalacticCowboy's answer to fix some issues and update for all (I think) SQL Server 2008R2 datatypes:

select data_type + 
    case
        when data_type like '%text' or data_type in ('image', 'sql_variant' ,'xml')
            then ''
        when data_type in ('float')
            then '(' + cast(coalesce(numeric_precision, 18) as varchar(11)) + ')'
        when data_type in ('datetime2', 'datetimeoffset', 'time')
            then '(' + cast(coalesce(datetime_precision, 7) as varchar(11)) + ')'
        when data_type in ('decimal', 'numeric')
            then '(' + cast(coalesce(numeric_precision, 18) as varchar(11)) + ',' + cast(coalesce(numeric_scale, 0) as varchar(11)) + ')'
        when (data_type like '%binary' or data_type like '%char') and character_maximum_length = -1
            then '(max)'
        when character_maximum_length is not null
            then '(' + cast(character_maximum_length as varchar(11)) + ')'
        else ''
    end as CONDENSED_TYPE
    , *
from information_schema.columns
order by table_schema, table_name, ordinal_position

這篇關(guān)于如何使用括號(hào)和所有內(nèi)容獲取 SQL Server 列定義?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

What SQL Server Datatype Should I Use To Store A Byte[](我應(yīng)該使用什么 SQL Server 數(shù)據(jù)類型來存儲(chǔ)字節(jié) [])
Interpreting type codes in sys.objects in SQL Server(解釋 SQL Server 中 sys.objects 中的類型代碼)
Typeorm .loadRelationCountAndMap returns zeros(Typeorm .loadRelationCountAndMap 返回零)
MS SQL: Should ISDATE() Return quot;1quot; when Cannot Cast as Date?(MS SQL:ISDATE() 是否應(yīng)該返回“1?什么時(shí)候不能投射為日期?)
Converting the name of a day to its integer representation(將一天的名稱轉(zhuǎn)換為其整數(shù)表示)
How to convert nvarchar m/d/yy to mm/dd/yyyy in SQL Server?(如何在 SQL Server 中將 nvarchar m/d/yy 轉(zhuǎn)換為 mm/dd/yyyy?)
主站蜘蛛池模板: 久久久三级 | 日韩少妇av | 一级片免费 | 中文字幕在线不卡 | 四虎三级 | 小sao货撅起屁股扒开c微博 | 婷婷狠狠 | 国产午夜精品视频 | 日本不卡一区二区 | 国产一区二区三区视频 | 色交视频| 长河落日电视连续剧免费观看 | 超碰97在线播放 | 人人干人人爱 | 欧美日韩视频在线 | 国内精品一区二区三区 | 亚洲午夜激情 | 午夜天堂在线 | 中文精品一区 | 欧美日韩一区在线观看 | www.超碰| av在线播放观看 | 亚洲成a人 | 精品在线免费视频 | 欧美国产在线视频 | 天天干天天操天天摸 | 亚洲激情在线视频 | 一区二区精品在线 | 中文字字幕 | 国产精品视频网站 | 91精品久久香蕉国产线看观看 | 久久久免费看 | 国产又爽又黄免费视频 | 国产精品久久免费 | 欧美a级成人淫片免费看 | 日韩欧美在线视频 | 日韩精品小视频 | a视频| 五月天网址 | 午夜免费小视频 | 国产黄av|