2025-01-05

The obscure star-database

To play around with some obscrure naming possibilities in SQL Server I create the star-database. The name has nothing to do with the data warehouse star-schema pattern. The name is because the database is named with the star character (*).

CREATE DATABASE [*]
    ON PRIMARY ( NAME = N'star_data', FILENAME = N'L:\SSDB2019\Data\star_data.mdf', SIZE = 8MB, FILEGROWTH = 8MB )
    LOG ON ( NAME = N'star_log', FILENAME = N'L:\SSDB2019\TransLog\star_log.ldf', SIZE = 8MB, FILEGROWTH = 8MB );

The database is created on specific directory as inplicit default path using only the database name does not work. This was expected. Using the star-character as name requires me to wrap the name in [].

In the star-database I then create a star-schema.

USE [*];
GO
CREATE SCHEMA [*] AUTHORIZATION [dbo];

... and then a star-table.

CREATE TABLE [*].[*]
(
    [*] bigint NOT NULL IDENTITY (0, 2),
    [%] nvarchar(42) NULL,
    [<] int null,
    [>] int null
);
GO
ALTER TABLE [*].[*] ADD CONSTRAINT
    [PK_star] PRIMARY KEY CLUSTERED 
    ([*]) ON [PRIMARY];

The column names are are almost as obscure as the other names. And then I insert a few rows.

INSERT INTO [*].[*] ([%],[<],[>])
VALUES
    (N'række0', 1000, -1000),
    (N'rÆkke1', 10, -100),
    (N'räkke2', 237, 7);

Then I can select the table in different ways, where the syntax is quite important to the output.

SELECT [*] FROM [*].[*];
SELECT * FROM [*].[*];
SELECT COUNT(*) AS [**] FROM [*].[*];

The first two statements visually looks similar, but the [] makes quite a difference. Adding some WHERE-clauses also adds to the fun.

SELECT * FROM [*].[*] WHERE [%] LIKE '%ä%';
SELECT * FROM [*].[*] WHERE [<]<500;
SELECT * FROM [*].[*] WHERE [>]<0;

The script is in SQLAdmin Github (star_database.sql). Next round could be adding more fun with unicode...

The obscure master-database

The master database is well known. And creating a database with a similar name can make things obscure or unexpected. Playing with adding space before or after "master" is only partly possible. Adding a space after the name as [master ] does not work and gives the error "Msg 1801, Level 16, State 3, Line 8 Database 'master ' already exists. Choose a different database name.". But adding a space after like [ master] does work.

CREATE DATABASE [ master] ON  PRIMARY 
( NAME = N'master0_data', FILENAME = N'L:\SSDB2019\Data\master0_data.mdf', SIZE = 8MB, FILEGROWTH = 8MB )
LOG ON 
( NAME = N'master0_log', FILENAME = N'L:\SSDB2019\TransLog\master0_log.ldf', SIZE = 8MB, FILEGROWTH = 8MB );

Adding other characters known from other parts of a database can add to the obscure situation.

CREATE DATABASE [master.] ON  PRIMARY 
( NAME = N'master_dot_data', FILENAME = N'L:\SSDB2019\Data\master_dot_data.mdf', SIZE = 8MB, FILEGROWTH = 8MB )
 LOG ON 
( NAME = N'master_dot_log', FILENAME = N'L:\SSDB2019\TransLog\master_dot_log.ldf', SIZE = 8MB, FILEGROWTH = 8MB );
GO

CREATE DATABASE [master.dbo] ON  PRIMARY 
( NAME = N'master_dbo_data', FILENAME = N'L:\SSDB2019\Data\master_dbo_data.mdf', SIZE = 8MB, FILEGROWTH = 8MB )
 LOG ON 
( NAME = N'master_dbo_log', FILENAME = N'L:\SSDB2019\TransLog\master_dbo_log.ldf', SIZE = 8MB, FILEGROWTH = 8MB );

The script file with the obscure master databases is also in SQLAdmin Github in obscure_master_database.sql.

No comments: