A PHP-based web tool for Database Administrators to detect and resolve schema drift between two Microsoft SQL Server databases β via live connection or uploaded .sql DDL files.
In multi-environment SQL Server setups (Dev β UAT β Production) or multi-tenant deployments, databases are expected to share an identical schema but serve different data. Over time, schema drift occurs β a missing index here, an unapplied constraint there β causing silent bugs, performance issues, or broken application logic.
SQLDBCompare gives DBAs a fast, reliable way to catch these differences and get a ready-to-run T-SQL fix script in one go.
- π Two Input Modes β connect live to SQL Server or upload two
.sqlDDL files - π TrustServerCertificate Support β compatible with SQL Server 2019+ and SSMS 19+
- π§© Deep Schema Comparison across all major object types:
- Tables & Columns (type, nullability, defaults)
- Primary Keys & Foreign Keys
- Unique, Check & Default Constraints
- Non-Clustered & Clustered Indexes (with included columns + filter definitions)
- Triggers
- π Colour-Coded HTML Report with per-category tabbed view
- π Downloadable T-SQL Fix Script β review and run directly against your target DB
β οΈ Missing Table Detection β flags tables present in one DB but absent in the other- π‘οΈ Security-First β parameterised queries, upload validation, XSS-sanitised output
| Layer | Technology |
|---|---|
| Language | PHP 8.1+ |
| DB Driver | sqlsrv / pdo_sqlsrv (Microsoft) |
| Frontend | HTML5 + Bootstrap 5 |
| Schema Queries | SQL Server DMVs & INFORMATION_SCHEMA views |
| SQL Parsing | Custom PHP DDL parser |
| Output | HTML Report + .sql Fix Script |
| Launcher | C# (Launcher.cs) β optional desktop launcher |
| Build | PowerShell (build_dist.ps1) β distribution packager |
extension=sqlsrv
extension=pdo_sqlsrvLinux (Ubuntu/Debian):
sudo apt install php8.1-dev unixodbc-dev
pecl install sqlsrv pdo_sqlsrvWindows (XAMPP / Laragon):
Download php_sqlsrv_81_ts_x64.dll and php_pdo_sqlsrv_81_ts_x64.dll from the Microsoft PHP Driver releases and place them in your PHP ext/ directory.
Required by the sqlsrv extension.
β Install ODBC Driver for SQL Server
# Clone the repository
git clone https://github.com/nileshmishra46/SQLDBCompare.git
cd SQLDBCompare
# Set permissions for upload and output directories
chmod 750 uploads/
chmod 750 output/fix_scripts/
# Configure settings
cp config/settings.example.php config/settings.phpOpen config/settings.php and adjust as needed:
return [
'trust_server_certificate' => true, // Required for SQL Server 2019+ / SSMS 19+
'encrypt' => true,
'default_port' => 1433,
'upload_max_size_mb' => 20,
'comparison_ignore_case' => true,
];Serve via Apache/Nginx or PHP's built-in server:
php -S localhost:8080Then open http://localhost:8080 in your browser.
Windows users: You can also use
Launcher.csto launch the tool as a desktop application, or runbuild_dist.ps1to package a distributable release.
SQLDBCompare/
βββ index.php # Mode selector (Live DB or File Upload)
βββ connect.php # Live connection form + handler
βββ upload.php # .sql file upload form + handler
βββ compare.php # Comparison controller
βββ report.php # HTML diff report renderer
βββ run_tests.php # Test runner for comparison engine
βββ Launcher.cs # Optional C# desktop launcher (Windows)
βββ build_dist.ps1 # PowerShell build & distribution packager
βββ .gitignore
β
βββ engine/
β βββ DbInspector.php # Fetches schema via DMVs from live SQL Server
β βββ SqlFileParser.php # Parses uploaded .sql DDL files
β βββ SchemaComparator.php # Produces structured diff between two schemas
β βββ ScriptGenerator.php # Generates T-SQL fix scripts from diff
β
βββ config/
β βββ db.php # PDO connection helper (TrustServerCertificate)
β βββ settings.php # App configuration
β
βββ assets/
β βββ css/style.css
β βββ js/app.js
β
βββ uploads/ # Temp storage for uploaded .sql files
βββ output/fix_scripts/ # Generated .sql fix files per run
ββββββββββββββββββββββββββββββββββββ
β Choose Input Mode β
β A) Live SQL Server Connection β
β B) Upload .sql DDL Files β
ββββββββββββββββ¬ββββββββββββββββββββ
β
βββββββββΌβββββββββ
β Schema Fetcher β β DbInspector (live) or SqlFileParser (file)
βββββββββ¬βββββββββ
β
βββββββββΌβββββββββ
β Comparator β β Compares Source vs Target across all object types
βββββββββ¬βββββββββ
β
ββββββββββββ΄βββββββββββ
β β
βββββΌβββββββββ ββββββββββΌβββββββββββ
β HTML Reportβ β T-SQL Fix Script β
β (browser) β β (.sql download) β
ββββββββββββββ βββββββββββββββββββββ
| Object | Compared By |
|---|---|
| Tables | Presence in both DBs |
| Columns | Name, data type, length, nullability, default value |
| Primary Keys | Constraint name, column(s), key order |
| Foreign Keys | Constraint name, parent/reference table & column, ON DELETE/UPDATE action |
| Unique Constraints | Constraint name, column(s) |
| Check Constraints | Constraint name, check expression |
| Default Constraints | Constraint name, column, default value expression |
| Indexes | Name, type (clustered/nonclustered), columns, included columns, filter, uniqueness |
| Triggers | Name, parent table, event type, enabled/disabled state |
-- Generated by SQLDBCompare
-- Run Date: 2025-06-12
-- Source: ProductionDB | Target: StagingDB
-- WARNING: Review before executing in production
USE [StagingDB];
GO
-- MISSING INDEX: IX_Orders_CustomerId on dbo.Orders
CREATE NONCLUSTERED INDEX [IX_Orders_CustomerId]
ON [dbo].[Orders] ([CustomerId] ASC)
INCLUDE ([OrderDate], [Status]);
GO
-- MISSING FOREIGN KEY: FK_Orders_Customers on dbo.Orders
ALTER TABLE [dbo].[Orders]
ADD CONSTRAINT [FK_Orders_Customers]
FOREIGN KEY ([CustomerId])
REFERENCES [dbo].[Customers] ([CustomerId])
ON DELETE NO ACTION ON UPDATE NO ACTION;
GO- All schema queries use SQL Server system views β no user input is interpolated into SQL
- Credentials are held only in the PHP session and never logged or stored
- Uploaded files are validated by extension and MIME type, stored outside the web root
- All DB object names are
htmlspecialchars()escaped before rendering in the report
- Stored procedure & view comparison
- Three-way compare (Dev / UAT / Prod)
- Email report delivery
- Scheduled nightly comparison with drift alerts
- Apply fix script directly to Target DB (with confirmation step)
- Comparison history log (SQLite)
- REST API mode (JSON in / JSON out)
Pull requests are welcome. For major changes, please open an issue first to discuss what you'd like to change.
- Fork the repository
- Create your feature branch (
git checkout -b feature/stored-proc-compare) - Commit your changes (
git commit -m 'Add stored procedure comparison') - Push to the branch (
git push origin feature/stored-proc-compare) - Open a Pull Request
Nilesh Mishra β Database Administrator
- GitHub: https://github.com/nileshmishra46
- LinkedIn: https://www.linkedin.com/in/nilesh46/