Obtain SQL Server table information

Source: Internet
Author: User
Python. dzone. comarticleswxpython-how-use-clipboardSQLServerexecsp_gtcEmployeeTabularUnsortedexecsp_gtcEmployee0, 1TabularSortedexecsp_gtcEmployee1, 0CSVUnsortedexecsp_gtcEmployee1, 1 CSVSortedUSEmaste

Http://python.dzone.com/articles/wxpython-how-use-clipboard SQL Server exec sp_gtc 'Employee' Tabular/Unsortedexec sp_gtc 'Employee' 0, 1 Tabular/Sortedexec sp_gtc 'Employee' 1, 0 CSV/Unsortedexec sp_gtc 'Employee' 1, 1 CSV/Sorted USE maste

Http://python.dzone.com/articles/wxpython-how-use-clipboard
SQL Server
exec sp_gtc 'Employee'         Tabular/Unsortedexec sp_gtc 'Employee' 0, 1    Tabular/Sortedexec sp_gtc 'Employee' 1, 0    CSV/Unsortedexec sp_gtc 'Employee' 1, 1    CSV/Sorted
USE masterGOIF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sp_GTC]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sp_GTC]GO-- =============================================-- Author:      David Elliott-- Create date: 05/01/2012-- Description: Return table information---- INPUT--    @tableName      Name of the table to get information about--    @display        0 = Tabular, 1 = CSV--    @orderByName    0 = No,      1 = Yes-- =============================================CREATE PROCEDURE sp_GTC      @tableName      VARCHAR(255)    ,@display        TINYINT  = 0    ,@orderByName    BIT      = 0AS    SET NOCOUNT ON    DECLARE @tableColumns TABLE    (         column_id      INT        ,column_name    VARCHAR(200)        ,dataType       VARCHAR(200)        ,max_length     INT        ,precision      TINYINT        ,scale          INT        ,is_nullable    BIT        ,is_identity    BIT    )    INSERT INTO @tableColumns (c.column_id, column_name, dataType, max_length, precision, scale, is_nullable, is_identity)    SELECT c.column_id, c.name AS column_name, ct.name as dataType, c.max_length, c.precision, c.scale, c.is_nullable, c.is_identity    FROM sys.columns c        INNER JOIN sys.tables t ON c.object_id = t.object_id        INNER JOIN sys.types ct ON c.system_type_id = ct.system_type_id    WHERE t.name = @tableName    IF (@display = 0)    BEGIN        SELECT *         FROM @tableColumns         ORDER BY CASE WHEN @orderByName = 0             THEN REPLACE(STR(column_id, 4), SPACE(1), '0')             ELSE column_name             END    END    ELSE IF (@display = 1)    BEGIN        SELECT SUBSTRING(        (            SELECT ', ' + column_name            FROM @tableColumns            ORDER BY CASE WHEN @orderByName = 0                 THEN REPLACE(STR(column_id, 4), SPACE(1), '0')                 ELSE column_name                 END            FOR XML PATH('')        ), 2, 200000) AS CSV    ENDGOEXEC sys.sp_MS_marksystemobject sp_GTCGO

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.