Script a SQL Server Database to a .sql File — With the Data, Not Just the Schema (No Wizard Needed)
Here is a restore that "worked". The script ran clean — no errors, nothing red — and rebuilt the database perfectly… except every table came back with zero rows . The shape was copied. The data never was. It is the most common Generate Scripts mistake there is, and it fails silently. The fix is one setting. But to see it clearly, it helps to know what the Generate Scripts wizard in SSMS actually is : a front-end . Clicking through it does not write your script — it collects your choices, sets them as options on SQL Server's scripting engine (SMO, the Scripter), and lets the engine write the file. In this post we call that engine directly, from the terminal, with Microsoft's own scripter tool — same engine, same output file — and we count the rows before and after, twice. Every output below is from the real run (SQL Server 2025, on Linux). The map — everything follows it: a database → the Scripter → one .sql file → a new database that proves the copy. W...