You cannot use explicit BACKUP DATABASEfor this. However, you can do something similar, however keep in mind that, as in my commentary, this data will be limited if you rely on any kind of data integrity, since the ordering will be relatively arbitrary, and if all is not 1 : 1 and you get a magically convenient sorting for all requests, it will be just a massive data object:
CREATE DATABASE copy_of_original;
GO
USE original_db;
GO
DECLARE @sql NVARCHAR(MAX);
SET @sql = N'';
SELECT @sql = @sql + CHAR(13) + CHAR(10)
+ 'SELECT TOP (100) * INTO copy_of_original.dbo.'
+ QUOTENAME(name) + ' FROM dbo.' + QUOTENAME(name) + ';'
FROM sys.tables
WHERE schema_id = 1;
PRINT @sql;
Once you do this, you can make a backup copy_of_originalโ but keep in mind that it will not have any indexes or restrictions present in the source database, and that it TOPwill select an arbitrary set of 100 rows from each table (or the whole table, for small tables with less than 100 rows).
source
share