Syntax for INSERTing into a table with no values?

27,123

See this (example "F. Load data using the DEFAULT VALUES option"):

INSERT INTO [Visualizations] DEFAULT VALUES;
Share:
27,123
David Pfeffer
Author by

David Pfeffer

I'm the CTO of the startup company FunnelFire, where we build a sophisticated real-time sales intelligence platform. I'm also an adjunct professor of Computer Science at Stevens Institute of Technology, where I teach a variety of courses from Introduction to C++11, to Data Structure and Algorithms, to TCP/IP Networking (an advanced programming course where students re-implement the network stack). I graduated in 2009 from Stevens Institute of Technology with a bachelors and masters of science in Computer Science, a minor in Law & Public Policy, and graduate certificates in Computer Systems, Databases & Service Oriented Architecture, Distributed Systems, Enterprise Computing, Quantitative Software Engineering, and Service Oriented Computing. I got my start programming at a very young age, writing QBasic programs to display colorful circles on the screen while sitting on my dad's lap when I was 3 years old. My first big projects were a Super Mario World clone for GameBoy, a MUD called HybridMOO, and a home automation package called IntellHome (which I still use!). I'm actively involved in a number of open source initiatives, including an open-source middleware tool called PushoverQ. I am interested in hiking, exploration of abandoned or neglected sites and buildings, photography (particularly of those abandoned sites, but also glamour/editorial), cooking, snowshoeing, and New Jersey trivia/history.

Updated on July 05, 2022

Comments

  • David Pfeffer
    David Pfeffer almost 2 years

    I have a table created with the following schema:

    CREATE TABLE [dbo].[Visualizations]
    (
        VisualizationID     int identity (1,1)      NOT NULL
    )
    

    Since the table has no settable fields, I'm not sure how to insert a record. I tried:

    INSERT INTO [Visualizations];
    INSERT INTO [Visualizations] () VALUES ();
    

    Neither work. What is the proper syntax to do this?

    Edit: Since a number of people seem confused by my table, it is used purely to represent a parent of a number of sub-tables... each one references this table by FK and each of those FKs are PKs, so that across all of those tables, the IDs are unique.

  • Mark Goldfain
    Mark Goldfain over 7 years
    In SQL Server, using TSQL, this statement gives an error: "DEFAULT or NULL are not allowed as explicit identity values."
  • dakab
    dakab over 4 years
    Beautifully simple … new link here.
  • Matthew Walker
    Matthew Walker over 3 years
    Works in SQLite too.
  • Wong Jia Hau
    Wong Jia Hau almost 2 years
    Works in Postgres too