Home Database Mysql Tutorial 获取mssql 表的结构

获取mssql 表的结构

Jun 07, 2016 pm 03:13 PM
mssql formulate only structure Script Obtain

获取 制定表的 结构 . ---此脚本只有在sql server 2000下面有效. go create proc getTableStruct @tabName varchar(20) as SELECT 表名 = case when a.colorder=1 then d.name else '' end, 表说明 = case when a.colorder=1 then isnull(f.value,'') else '

获取制定表的结构.
---此脚本只有在sql server 2000下面有效.

go
create proc getTableStruct
@tabName varchar(20)
as
SELECT    
          表名           =   case   when   a.colorder=1   then   d.name   else   ''   end,  
          表说明           =   case   when   a.colorder=1   then   isnull(f.value,'')   else   ''   end,  
          字段序号       =   a.colorder,  
          字段名           =   a.name,  
          标识               =   case   when   COLUMNPROPERTY(   a.id,a.name,'IsIdentity')=1   then   '√'else   ''   end,  
          主键               =   case   when   exists(SELECT   1   FROM   sysobjects   where   xtype='PK'   and   parent_obj=a.id   and   name   in   (  
                                            SELECT   name   FROM   sysindexes   WHERE   indid   in(  
                                                  SELECT   indid   FROM   sysindexkeys   WHERE   id   =   a.id   AND   colid=a.colid)))   then   '√'   else   ''   end,  
          类型               =   b.name,  
          占用字节数   =   a.length,  
          长度               =   COLUMNPROPERTY(a.id,a.name,'PRECISION'),  
          小数位数       =   isnull(COLUMNPROPERTY(a.id,a.name,'Scale'),0),  
          允许空           =   case   when   a.isnullable=1   then   '√'else   ''   end,  
          默认值           =   isnull(e.text,''),  
          字段说明       =   isnull(g.[value],'')  
FROM    
          syscolumns   a  
left   join    
          systypes   b    
on    
          a.xusertype=b.xusertype  
inner   join    
          sysobjects   d    
on    
          a.id=d.id     and   d.xtype='U'   and     d.name'dtproperties'  
left   join    
          syscomments   e    
on    
          a.cdefault=e.id  
left   join    
          sysproperties   g    
on    
          a.id=g.id   and   a.colid=g.smallid      
left   join    
          sysproperties   f    
on    
          d.id=f.id   and   f.smallid=0  
where    
          d.name in (@tabName)        --如果只查询指定表,加上此条件  
order   by    
          a.id,a.colorder

exec getTableStruct spt_values

---此脚本作用是获取制定表的结构.
---版本:sql server2005
use handk
if exists(
select * from sysobjects where name='getTableStruct' and type='P'
)
drop proc getTableStruct
go
create proc getTableStruct
@tabName varchar(20)
as
SELECT    
          表名           =   case   when   a.colorder=1   then   d.name   else   ''   end,  
          表说明           =   case   when   a.colorder=1   then   isnull(f.value,'')   else   ''   end,  
          字段序号       =   a.colorder,  
          字段名           =   a.name,  
          标识               =   case   when   COLUMNPROPERTY(   a.id,a.name,'IsIdentity')=1   then   '√'else   ''   end,  
          主键               =   case   when   exists(SELECT   1   FROM   sysobjects   where   xtype='PK'   and   parent_obj=a.id   and   name   in   (  
                                            SELECT   name   FROM   sysindexes   WHERE   indid   in(  
                                                  SELECT   indid   FROM   sysindexkeys   WHERE   id   =   a.id   AND   colid=a.colid)))   then   '√'   else   ''   end,  
          类型               =   b.name,  
          占用字节数   =   a.length,  
          长度               =   COLUMNPROPERTY(a.id,a.name,'PRECISION'),  
          小数位数       =   isnull(COLUMNPROPERTY(a.id,a.name,'Scale'),0),  
          允许空           =   case   when   a.isnullable=1   then   '√'else   ''   end,  
          默认值           =   isnull(e.text,''),  
          字段说明       =   isnull(g.[value],'')  
FROM    
          syscolumns   a  
left   join    
          systypes   b    
on    
          a.xusertype=b.xusertype  
inner   join    
          sysobjects   d    
on    
          a.id=d.id     and   d.xtype='U'   and     d.name'dtproperties'  
left   join    
          syscomments   e    
on    
          a.cdefault=e.id  
left   join    
      sys.extended_properties    g     ---这里与sql server 2000 有不同之处
on    
A.ID=G.major_id   AND   A.COLID=G.minor_id  
left   join    
        sys.extended_properties    f    
on    
      D.ID=F.major_id   AND   F.minor_id=0
where    
          d.name in (@tabName)        --如果只查询指定表,加上此条件  
order   by    
          a.id,a.colorder

go
exec getTableStruct Item

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to create a script for editing? Tutorial on how to create a script through editing How to create a script for editing? Tutorial on how to create a script through editing Mar 13, 2024 pm 12:46 PM

Cutting is a video editing tool with comprehensive editing functions, support for variable speed, various filters and beauty effects, and rich music library resources. In this software, you can edit videos directly or create editing scripts, but how to do it? In this tutorial, the editor will introduce the method of editing and making scripts. Production method: 1. Click to open the editing software on your computer, then find the "Creation Script" option and click to open. 2. In the creation script page, enter the "script title", and then enter a brief introduction to the shooting content in the outline. 3. How can I see the "Storyboard Description" option in the outline?

How to execute .sh file in Linux system? How to execute .sh file in Linux system? Mar 14, 2024 pm 06:42 PM

How to execute .sh file in Linux system? In Linux systems, a .sh file is a file called a Shell script, which is used to execute a series of commands. Executing .sh files is a very common operation. This article will introduce how to execute .sh files in Linux systems and provide specific code examples. Method 1: Use an absolute path to execute a .sh file. To execute a .sh file in a Linux system, you can use an absolute path to specify the location of the file. The following are the specific steps: Open the terminal

Where to get Google security code Where to get Google security code Mar 30, 2024 am 11:11 AM

Google Authenticator is a tool used to protect the security of user accounts, and its key is important information used to generate dynamic verification codes. If you forget the key of Google Authenticator and can only verify it through the security code, then the editor of this website will bring you a detailed introduction on where to get the Google security code. I hope it can help you. If you want to know more Users please continue reading below! First open the phone settings and enter the settings page. Scroll down the page and find Google. Go to the Google page and click on Google Account. Enter the account page and click View under the verification code. Enter your password or use your fingerprint to verify your identity. Obtain a Google security code and use the security code to verify your Google identity.

How to connect php to mssql database How to connect php to mssql database Oct 23, 2023 pm 12:02 PM

Methods for php to connect to mssql database include using PHP's MSSQL extension, using PDO, etc. Detailed introduction: 1. Use PHP's MSSQL extension method to ensure that PHP has the MSSQL extension installed. You can check whether the mssql extension is enabled in the PHP configuration file (php.ini); 2. Use the PDO method to ensure that PHP has the PDO extension installed. You can check whether the pdo_sqlsrv extension is enabled in the PHP configuration file (php.ini).

Detailed guide to install PHP and configure MSSQL connection on Ubuntu Detailed guide to install PHP and configure MSSQL connection on Ubuntu Feb 29, 2024 am 11:15 AM

Ubuntu is a popular open source operating system commonly used to run servers. Installing PHP and configuring MSSQL connections on Ubuntu is one of the operations that many developers and system administrators often need to do. This article will provide readers with a detailed guide, including the steps to install PHP, set up Apache, install MSSQLServer, etc., and attach specific code examples. Step 1: Install PHP and related extensions First, we need to install PHP and related extensions to support PHP connections

Windows PowerShell Scripting Tutorial for Beginners Windows PowerShell Scripting Tutorial for Beginners Mar 13, 2024 pm 10:55 PM

We've designed this Windows PowerShell scripting tutorial for beginners, whether you're a tech enthusiast or a professional looking to improve your scripting skills. If you have no prior knowledge of PowerShell scripting, this article will start with the basics and be tailored for you. We'll help you master the installation steps for a PowerShell environment and walk you through the main concepts and features of PowerShell scripts. If you're ready to learn more about PowerShell scripting, let's embark on this exciting learning journey together! What is WindowsPowerShell? PowerShell is a hybrid command system developed by Microsoft

How to install dual SIM on Realme 12 Pro? How to install dual SIM on Realme 12 Pro? Mar 18, 2024 pm 02:10 PM

Although the general operations of domestic mobile phones are very similar, there are still some differences in some details. For example, different mobile phone models and manufacturers may have different dual-SIM installation methods. Erzhenwo 12Pro, a new mobile phone, also supports dual-SIM dual standby, but how should dual-SIM be installed on this phone? How to install dual SIM on Realme 12Pro? Remember to turn off your phone before installation. Step 1: Find the SIM card tray: Find the SIM card tray of the phone. Usually, in the Realme 12 Pro, the SIM card tray is located on the side or top of the phone. Step 2: Insert the first SIM card. Use a dedicated SIM card pin or a small object to insert it into the slot in the SIM card tray. Then, carefully insert the first SIM card.

Simple JavaScript Tutorial: How to Get HTTP Status Code Simple JavaScript Tutorial: How to Get HTTP Status Code Jan 05, 2024 pm 06:08 PM

JavaScript tutorial: How to get HTTP status code, specific code examples are required. Preface: In web development, data interaction with the server is often involved. When communicating with the server, we often need to obtain the returned HTTP status code to determine whether the operation is successful, and perform corresponding processing based on different status codes. This article will teach you how to use JavaScript to obtain HTTP status codes and provide some practical code examples. Using XMLHttpRequest

See all articles