Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. SQL Server Structure Access

SQL Server Structure Access

Scheduled Pinned Locked Moved C#
csharpdatabasesql-serverdotnetsysadmin
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Mark Sanders
    wrote on last edited by
    #1

    Does anyone know if it is possible, using C# and the .NET framework, to get access to the structure of databases in SQL Server? When I say "structure" I mean for example, a programmatic way to get the name of all the tables and their fields and relations, when you know nothing about the database except a connection string for it. Mark Sanders

    D 1 Reply Last reply
    0
    • M Mark Sanders

      Does anyone know if it is possible, using C# and the .NET framework, to get access to the structure of databases in SQL Server? When I say "structure" I mean for example, a programmatic way to get the name of all the tables and their fields and relations, when you know nothing about the database except a connection string for it. Mark Sanders

      D Offline
      D Offline
      Daniel Turini
      wrote on last edited by
      #2

      Search MSDN for "sysobjects". It's a "table" where this kind of metadata information is available and it's fully documented on MSDN. As a sample, if you want the list of all the tables on the current database, run:

      select name from sysobjects where xtype = 'U'

      ORACLE One Real A$#h%le Called Lary Ellison

      A 1 Reply Last reply
      0
      • D Daniel Turini

        Search MSDN for "sysobjects". It's a "table" where this kind of metadata information is available and it's fully documented on MSDN. As a sample, if you want the list of all the tables on the current database, run:

        select name from sysobjects where xtype = 'U'

        ORACLE One Real A$#h%le Called Lary Ellison

        A Offline
        A Offline
        Arjan Einbu
        wrote on last edited by
        #3

        The system tables are subject to change in future versions of SQL server. (They have changed before) The recomended approach is to use the INFORMATION_SCHEMA views and some system stored procedures, since MS have committed to keep the output of these compatible through all versions on SQL Server they exist on, and they will exist on all future releases of SQL Server. (Meaning MS has added some, but not removed any of them...) Usage example: SELECT * FROM INFORMATION_SCHEMA.TABLES Lookup in BOL's index on INFORMATION_SCHEMA

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups