forked from ktaranov/sqlserver-kit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCreate_2_Millions_Tables.sql
43 lines (30 loc) · 1.06 KB
/
Create_2_Millions_Tables.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/*
https://docs.microsoft.com/en-us/sql/sql-server/maximum-capacity-specifications-for-sql-server?view=sql-server-2017
Database objects include objects such as tables, views, stored procedures, user-defined functions, triggers, rules, defaults, and constraints.
The sum of the number of all objects in a database cannot exceed 2,147,483,647.
*/
CREATE DATABASE TwoMillions;
GO
ALTER DATABASE TwoMillions SET RECOVERY SIMPLE WITH NO_WAIT;
USE TwoMillions;
GO
SET NOCOUNT ON;
DECLARE @tsql nvarchar(max) = N'';
DECLARE @tsqlTemplate nvarchar(max) = N'CREATE TABLE t_i_ (c_i_ int); INSERT INTO t_i_ VALUES(_i_);';
DECLARE @i int = 1;
SELECT @i = COUNT(*) + 1 FROM TwoMillions.sys.tables;
WHILE @i < 2147483648
BEGIN
SET @tsql = REPLACE(@tsqlTemplate, N'_i_', CAST(@i AS nvarchar(max)));
--RAISERROR(@tsql, 0, 1) WITH NOWAIT;
EXEC sp_executesql @tsql;
SET @i = @i +1;
IF (@i % 10000) = 0 RAISERROR(@i, 0, 1) WITH NOWAIT;;
END;
/*
ALTER DATABASE TwoMillions SET SINGLE_USER WITH ROLLBACK IMMEDIATE;
GO
USE master;
GO
DROP DATABASE TwoMillions;
*/