wise-coders / dbschema

DbSchema Database Designer
https://dbschema.com
67 stars 3 forks source link

Bug: SQL Server - Declaring Table variable results in weird behavior in scripts #121

Closed akarnavasco closed 1 month ago

akarnavasco commented 1 month ago

I get a weird behavior when declaring a Table variable in SqlServer Version 2022.

  1. Please check DbSchema Help / Output logs for errors. No errors reported in log. 16:00:42 > runScript

  2. Please include the DbSchema version, operating system and used database

    DB Schema version: DbSchema 9.5.4 build 240504 DbSchema Community Edition

    OS version: Ubuntu 22.04.4 LTS

    Database version: SqlServer Version 2022 Build version 16.0.4095.4

  3. The steps to reproduce this issue

    Run the following script (with auto-commit enabled)

    DECLARE @Columns100 TABLE (Name NVARCHAR(MAX));
    CREATE TABLE dummy33 (Name NVARCHAR(MAX));
    INSERT INTO dummy33 VALUES ('Value1'), ('Value2');
    SELECT * FROM dummy33;

    Expected Output:

    DECLARE @Columns100 TABLE (Name NVARCHAR(MAX));
    
    CREATE TABLE dummy33 (Name NVARCHAR(MAX));
    
    Modified -1 rows
    
    INSERT INTO dummy33 VALUES ('Value1'), ('Value2');
    
    Modified 2 rows
    
    SELECT * FROM dummy33;
    
    Name   
    ====== 
    Value1 
    Value2 
    
    Read 2 rows

    Actual Output:

    DECLARE @Columns100 TABLE (Name NVARCHAR(MAX));
    CREATE TABLE dummy33 (Name NVARCHAR(MAX));
    INSERT INTO dummy33 VALUES...
    
    Modified 2 rows

    Notes

  4. Schema is not auto-refreshing after running above script.

  5. The table dummy33 table is created and populated as expected but it appears that the Select statement does not run.

  6. Same behavior happens when declaring a table variable, populating the table and then querying the table:

    DECLARE @Columns100 TABLE (Name NVARCHAR(MAX));
    INSERT INTO @Columns100 VALUES ('Value1'), ('Value2');
    SELECT * FROM @Columns100;
  7. All above scripts run perfectly fine by the same user using SQL Server Management Studio as well as other db clients.

wise-coders commented 1 month ago

Please install the current beta: https://dbschema.com/beta.php The select statement seems to run. We have still to fix the schema auto-refresh, but we don't consider this as a priority issue.