Home > OS >  How can I write insert command correctly in SQL Server?
How can I write insert command correctly in SQL Server?

Time:12-26

I am trying to write some SQL code. I have a table and I want to add values to that table Tasks, but I am getting an error

Invalid Column Name "Manager"

over Task_Name. I identified Id as auto-incrementing with IDENTITY(1,1) and I have a BIT type value as default 0.

How should I write the expression of insert into?

Here is the code for creating:

CREATE TABLE Tasks
(
    ID INTEGER IDENTITY(1,1) NOT NULL PRIMARY KEY,
    Task_Name VARCHAR(100),
    Situation BIT DEFAULT 0
);

Here is the code for Insert Into:

INSERT INTO (ID, Task_Name, Situation) 
VALUES (1, "Manager");

CodePudding user response:

INSERT INTO Tasks (Task_Name) values ('Manager')
  • Don’t specify ID unless turning identity_insert on (column is marked as identity column)
  • Don’t include column names to insert default values
  • Use ' to quote strings

CodePudding user response:

INSERT INTO Tasks (Task_Name, Situation) VALUES ('Task_NameValue', 1);

  • Related