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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Script Check

Script Check

Scheduled Pinned Locked Moved Database
toolsquestionlearningcsharpdatabase
3 Posts 2 Posters 1 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
    Mustafa Ismail Mustafa
    wrote on last edited by
    #1

    I just want to double check if this script is on the right track.

    select t.name, count(c.column_id) as columns
    from sys.tables as t
    inner join sys.columns as c on t.object_id = c.object_id
    where schema_id = (select schema_id from sys.schemas where sys.schemas.name='EMR') -- Alter Schema name
    group by t.name
    order by [name] asc

    Basically I want to check for altered tables between two different databases, this ought to pull out all the tables in a schema and the number of columns for each table. Obviously, any changes on the table that don't affect the number of columns, I will not be alerted of.

    If the post was helpful, please vote, eh! Current activities: Book: Devils by Fyodor Dostoyevsky Project: Hospital Automation, final stage Learning: Image analysis, LINQ Now and forever, defiant to the end. What is Multiple Sclerosis[^]?

    M 1 Reply Last reply
    0
    • M Mustafa Ismail Mustafa

      I just want to double check if this script is on the right track.

      select t.name, count(c.column_id) as columns
      from sys.tables as t
      inner join sys.columns as c on t.object_id = c.object_id
      where schema_id = (select schema_id from sys.schemas where sys.schemas.name='EMR') -- Alter Schema name
      group by t.name
      order by [name] asc

      Basically I want to check for altered tables between two different databases, this ought to pull out all the tables in a schema and the number of columns for each table. Obviously, any changes on the table that don't affect the number of columns, I will not be alerted of.

      If the post was helpful, please vote, eh! Current activities: Book: Devils by Fyodor Dostoyevsky Project: Hospital Automation, final stage Learning: Image analysis, LINQ Now and forever, defiant to the end. What is Multiple Sclerosis[^]?

      M Offline
      M Offline
      Mycroft Holmes
      wrote on last edited by
      #2

      I prefer to use the information schema view - 'cause I can.

      SELECT Table_Name, COUNT(*)
      FROM INFORMATION_SCHEMA.COLUMNS
      WHERE TABLE_SCHEMA = 'STG'
      GROUP BY Table_Name

      M 1 Reply Last reply
      0
      • M Mycroft Holmes

        I prefer to use the information schema view - 'cause I can.

        SELECT Table_Name, COUNT(*)
        FROM INFORMATION_SCHEMA.COLUMNS
        WHERE TABLE_SCHEMA = 'STG'
        GROUP BY Table_Name

        M Offline
        M Offline
        Mustafa Ismail Mustafa
        wrote on last edited by
        #3

        See, this is why I love this site :-D I like your script better and will steal it! Now , to figure out how to realize that there are changes!

        If the post was helpful, please vote, eh! Current activities: Book: Devils by Fyodor Dostoyevsky Project: Hospital Automation, final stage Learning: Image analysis, LINQ Now and forever, defiant to the end. What is Multiple Sclerosis[^]?

        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