view structure of table in sql server2000 in Q.A.

  • Hello friends,

    As in Oracle Database we can check the structure of table by

    DESC <Table_Name>

    But Can we check the same in Sql Server2000?

    Thanks In Advance

    Shashank


    Regards,

    Papillon

  • sp_help <tableName>


    🙂

  • sp_help is pretty comprehensive...

    You can also query the system tables with something like:

    select * from syscolumns where id =

    (select id from sysobjects where name = )







    **ASCII stupid question, get a stupid ANSI !!!**

  • that should read...

    select * from syscolumns where id =

    (select id from sysobjects where name = 'tablename')







    **ASCII stupid question, get a stupid ANSI !!!**

  • Try this......this may also help as a base metadata view for generating other code.

    SELECT

     so.[name] AS 'TableName',

     sc.[name] AS 'ColumnName',

     st.[name] AS 'ColumnType',

     sc.length AS 'ColumnSize',

     CASE sc.isnullable

      WHEN 0 THEN 'No' ELSE 'Yes' END AS 'IsNullable',

     myTemp.RefColumn,

     myTemp.RefTable

    FROM

     sysobjects so

     INNER JOIN syscolumns sc ON

      so.[id] = sc.[id]

     INNER JOIN 

     systypes st ON

      sc.xtype = st.xtype

     LEFT OUTER JOIN(

     SELECT

      sfk.constid AS 'ConstraintID',

      sfk.fkeyid AS 'TableID',

      sfk.fkey AS 'ColumnID',

      sc.[name] AS 'RefColumn',

      so.[name] AS 'RefTable',

      sfk.rkeyid AS 'TableID Ref',

      sfk.rkey AS 'ColumnID Ref'

     FROM

      sysforeignkeys sfk

      INNER JOIN syscolumns sc ON

       sfk.rkeyid = sc.[id]

       AND

       sfk.rkey = sc.colid

      INNER JOIN sysobjects so ON

       sc.[id] = so.[id]

    &nbsp myTemp ON

      myTemp.TableID = sc.[id]

      AND

      myTemp.ColumnID = sc.colid 

    WHERE

     so.type = 'U'

     AND

     so.[name] NOT LIKE 'dt%'

     

    --SELECT * FROM syscolumns

    --SELECT * FROM systypes

  • You can also run the following:

    select * from information_schema.columns

    which will return all column information for each table in the current database

  • As long as you're using QA, why not just use the Object Browser and save some typing?

    Greg

    Greg

  • Drag 'N' Drop is your friend.

    If only it did the quoting properly when you drag the columns in

     

    --------------------
    Colt 45 - the original point and click interface

  • Hello friends,

     

    Thanks for that!!!!!!!!!!!!!!!!!!!!!!

    shashank


    Regards,

    Papillon

  • sp_columns tablename

  • Many ways to skin this cat - <;-) - though object browser is the way to go for a quick dekko!!!







    **ASCII stupid question, get a stupid ANSI !!!**

Viewing 11 posts - 1 through 10 (of 10 total)

You must be logged in to reply to this topic. Login to reply