Get the App
SLTechnology News&Howtos  ›  Database  › 

Display the field name and description of the data table by creating a stored procedure

Shulou Source: shulou.com Published: 2022-06-01 17:00:36 10月01日 Update

In the development of winform program, when it comes to the combined query of a table, the field name and description of the table will be extracted from the database, so that the user can choose the query. It is more troublesome to use statements in C #, and it is more convenient to write to the stored procedure.

USE [schoolDB] GO/* Object: StoredProcedure [dbo]. [sp_showcolumn] Script Date: 06 * / SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGOALTER proc [dbo]. [sp_showcolumn] @ tablename varchar (30) as select c.name as field name P.value as explains from sysobjects o left join syscolumns c on o.id=c.id left join sys.extended_properties p on p.major_id=c.id and p.minor_id=c.colid and p.nameplate description 'left join systypes t on c.xusertype=t.xusertypewhere o.typewritten description u' and o.name=@tablename

Sql statements that query for more information:

Select o.name as tableName,c.name as columnName,t.name as columnType,p.value as columnDescription from sysobjects o left join syscolumns c on o.id=c.id left join sys.extended_properties p on p.major_id=c.id and p.minor_id=c.colid and p.nameplate description 'left join systypes t on c.xusertype=t.xusertypewhere o.typewriter' and o.nameplate description cdxmain'

Tags: Queries fields statements data procedures storage information databases more users programs program development trouble caching development combination selection datasheets Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB MySQL Xiaomi Apple Shulou Technology