Zach's Mugspideyclick logo

GitHub

GitLab

Linkedin

Instagram

Youtube

SoundCloud

Email

SQL Playground

Script for finding all tables with column "changeMe" in it.

SELECT      c.name  AS 'ColumnName'
            ,t.name AS 'TableName'
FROM        sys.columns c
JOIN        sys.tables  t   ON c.object_id = t.object_id
WHERE       c.name LIKE '%changeMe%'
ORDER BY    TableName
            ,ColumnName;

Find how many rows each table has:

SELECT t.NAME AS TableName, SUM(p.rows) AS [RowCount]
FROM sys.tables t
INNER JOIN sys.indexes i ON t.OBJECT_ID = i.object_id
INNER JOIN sys.partitions p ON i.object_id = p.OBJECT_ID AND i.index_id = p.index_id
INNER JOIN sys.columns c on t.object_id = c.object_id
WHERE i.index_id <= 1
GROUP BY t.NAME, i.object_id, i.index_id, i.name
ORDER BY SUM(p.rows) DESC
;

Combine rows from two different tables and show me if one column is different from another column + a string:

SELECT
    ispmanage.domain_user.username,
    ispmanage.domain_user.password,
    name,
    email_address,
    home_phone,
    office_phone,
    su_ip, static_ip,
    static_netmask,
    REPLYATTR
FROM ispmanage.domain_user
LEFT JOIN radiator_broadband.SUBSCRIBERS
ON ispmanage.domain_user.email_address = radiator_broadband.SUBSCRIBERS.USERNAME
WHERE ispmanage.domain_user.is_deleted=0
AND ispmanage.domain_user.username like "bb%"
AND ispmanage.domain_user.email_address like "%@atcjet.net"
AND ispmanage.domain_user.email_address != CONCAT(ispmanage.domain_user.username, '@atcjet.net')
;

Remove leading Zeros (MySQL)

I don't feel great about it, but it seems to work:

REPLACE(LTRIM(REPLACE(RTRIM(THISCOLUMNNAME), '0', ' ')), ' ', '0')