Skip to content

SQL Server table variables not supported | SELECT columnName FROM @table #911

Closed

Description

@cdandoy

SQL Server supports storing data in table variables which are in-memory variants to temporary tables:

SELECT columnName FROM @table

https://docs.microsoft.com/en-us/sql/t-sql/data-types/table-transact-sql?view=sql-server-ver15#examples

Activity

  1. cdandoy commented on Dec 21, 2019

    @cdandoy
    Author

    Here are a couple of use cases:

    DECLARE @tableName TABLE (id INT);
    
    INSERT INTO @tableName VALUES (1);
    UPDATE @tableName SET id=2;
    UPDATE t SET id=3 FROM @tableName AS t;
    SELECT * FROM @tableName;
    DELETE FROM @tableName;
    DELETE t FROM @tableName as t;
    
    
    -- not valid:
    -- SELECT @tableName.* FROM @tableName;
    -- SELECT 1 INTO @tableName;
    -- TRUNCATE TABLE @tableName;
    -- CREATE INDEX idx ON @tableName(id);
    
    
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions