Skip to content

Synthetic Data — MSSQL

The Demo Factory dataset for MSSQL contains a single table for testing the MSSQL connection in Pirivision. For comprehensive analytics queries use the PostgreSQL dataset.


Created Table

The table is created in a separate schema named demo_fabrika; it will not conflict with your existing database objects.

-- Create schema if it does not exist
IF NOT EXISTS (SELECT 1 FROM sys.schemas WHERE name = 'demo_fabrika')
    EXEC ('CREATE SCHEMA demo_fabrika');
GO

CREATE TABLE demo_fabrika.vardiya_uretim (
    ts            date          NOT NULL,
    hat_id        nvarchar(20)  NOT NULL,
    makine_id     nvarchar(20)  NOT NULL,
    vardiya       nvarchar(10)  NOT NULL,
    urun_ailesi   nvarchar(20)  NOT NULL,
    uretim_adet   int           NOT NULL,
    hedef         int           NOT NULL
);

Data Generation Logic

Because T-SQL has no generate_series, the date sequence is built with a recursive CTE. The generated rows are multiplied by cross-joining with the machine and shift lists.

;WITH gun_serisi AS (
    -- Starting point: 30 days before today
    SELECT CAST(DATEADD(day, -30, GETDATE()) AS date) AS gun
    UNION ALL
    -- Each step advances one day
    SELECT DATEADD(day, 1, gun)
    FROM gun_serisi
    WHERE gun < CAST(GETDATE() AS date)
),
makineler AS (
    SELECT idx FROM (VALUES (1),(2),(3),(4),(5),(6)) AS m(idx)
),
vardiyalar AS (
    SELECT v FROM (VALUES (N'V1'),(N'V2'),(N'V3')) AS x(v)
)
INSERT INTO demo_fabrika.vardiya_uretim
    (ts, hat_id, makine_id, vardiya, urun_ailesi, uretim_adet, hedef)
SELECT
    g.gun,
    CASE WHEN m.idx <= 3 THEN N'HAT-1' ELSE N'HAT-2' END,
    N'M0' + CAST(m.idx AS nvarchar(1)),
    v.v,
    -- Random product family per row via NEWID()
    (SELECT TOP 1 u
     FROM (VALUES (N'Product-A'),(N'Product-B'),(N'Product-C'),(N'Product-D')) x(u)
     ORDER BY NEWID()),
    250 + ABS(CHECKSUM(NEWID())) % 200,   -- production count 250–449
    400                                    -- fixed target
FROM gun_serisi g
CROSS JOIN makineler m
CROSS JOIN vardiyalar v
OPTION (MAXRECURSION 100);

Result: 31 days × 6 machines × 3 shifts = 558 rows


Loading into the Database

Run the SQL script against your database:

sqlcmd -S <server> -U <user> -P <password> -d <database> -i demo_fabrika_mssql.sql

Running the script again is safe — the existing table is dropped first if it exists.


Adding to Pirivision

  1. Go to Port → New Data Source → MSSQL.
  2. Enter the server, database, and credentials.
  3. Click Test and Save to store the connection.

Once saved, an example query you can write in Compass:

SELECT TOP 50
    ts, hat_id, makine_id, vardiya, urun_ailesi, uretim_adet
FROM demo_fabrika.vardiya_uretim
WHERE ts >= DATEADD(day, -7, GETDATE())
ORDER BY ts DESC, hat_id;