Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How does sql get fields based on table names

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly explains "how to get fields according to table names by sql". Friends who are interested may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "sql how to get fields based on table names".

The copy code is as follows:

SELECT TableName = OBJECT_NAME (c.object_id), ColumnsName = c.name, Description = ex.value, ColumnType=t.name, Length=c.max_length FROM sys.columns c LEFT OUTER JOIN sys.extended_properties ex ON ex.major_id = c.object_id AND ex.minor_id = c.column_id AND ex.name = 'MS_Description' left outer join systypes t on c.system_type_id=t.xtype WHERE OBJECTPROPERTY (c.object_id,' IsMsShipped') = 0 AND OBJECT_NAME (c.object_id) = 'tablename'1. Get all database names: Select Name FROM Master..SysDatabases orDER BY Name 2. Get all table names: Select Name FROM DatabaseName..SysObjects Where XType='U' orDER BY Name XType='U': represents all user tables; XType='S': represents all system tables; 3. Get all the field names: Select Name FROM SysColumns Where id=Object_Id ('TableName') so far, I believe you have a better understanding of "how sql gets fields based on table names". You might as well do it in practice! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report