Ad Widget

Collapse

SQL Query Check tables

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • webgordy
    Junior Member
    • Jan 2006
    • 6

    #1

    SQL Query Check tables

    I am trying to figure out a way of querying my data base server running MS SQL Server. I need to check a table to see if it is empty or not. Then setup a trigger based off of time table has something in it. Example: tableA has data that needs to synch. Once it is synced the table is emptied. However is the sync fails the data will remain in the table. Is it possible to setup a sql query and a trigger that will do this.
    Check the table and if table has data for a period of 5 minutes for say send an alert.

    Thanks
  • nelsonab
    Senior Member
    Zabbix Certified SpecialistZabbix Certified Professional
    • Sep 2006
    • 1233

    #2
    Edit... DOH! I missed the "MS" in MS SQL. Sorry. :-(

    Another idea would be to query the DB with something like "select count(*) from <mytable>" if anything more than 0 is returned trigger, or you could store the value and trigger if the value is greater than 0 for a period of time. I've not done much windows scripting so I wouldn't know how to script this into windows.
    ----

    Here is an sql query which will generate the data you are looking for. You just need to adapt it into a script.

    Code:
    echo "show table status;" | mysql -h <your_mysql_host> -u <db_user> -p <database>| grep -w <table> | cut -f 5
    Be sure to fill in the angled bracket bits as appropriate.

    This will query the table status and return the number of rows in the table given. This will also prompt you for the MySQL password. Column 7 will give you the size of the table.

    Hope this helps.
    Last edited by nelsonab; 09-05-2008, 23:20.
    RHCE, author of zbxapi
    Ansible, the missing piece (Zabconf 2017): https://www.youtube.com/watch?v=R5T9NidjjDE
    Zabbix and SNMP on Linux (Zabconf 2015): https://www.youtube.com/watch?v=98PEHpLFVHM

    Comment

    • webgordy
      Junior Member
      • Jan 2006
      • 6

      #3
      Thanks

      Than you I am indeed using MS SQL server, but you have gave me a lot to go off. Thank you for your reply.

      Comment

      Working...