Reputation: 13
The error message showed error invalid column name when the column actually exists in the created table.
CREATE TABLE Worker (
WORKER_ID INT NOT NULL,
FIRST_NAME CHAR(25),
LAST_NAME CHAR(25),
SALARY INT,
JOINING_DATE DATETIME,
DEPARTMENT CHAR(25)
);
INSERT INTO Worker
(WORKER_ID, FIRST_NAME, LAST_NAME, SALARY, JOINING_DATE, DEPARTMENT) VALUES
(001, 'Monika', 'Arora', 100000, '14-02-20 09.00.00', 'HR'),
(002, 'Niharika', 'Verma', 80000, '14-06-11 09.00.00', 'Admin'),
(003, 'Vishal', 'Singhal', 300000, '14-02-20 09.00.00', 'HR'),
(004, 'Amitabh', 'Singh', 500000, '14-02-20 09.00.00', 'Admin'),
(005, 'Vivek', 'Bhati', 500000, '14-06-11 09.00.00', 'Admin'),
(006, 'Vipul', 'Diwan', 200000, '14-06-11 09.00.00', 'Account'),
(007, 'Satish', 'Kumar', 75000, '14-01-20 09.00.00', 'Account'),
(008, 'Geetika', 'Chauhan', 90000, '14-04-11 09.00.00', 'Admin');
I have succesfully created the table, I didn't see any typo in the column name. This code is copied from https://www.techbeamers.com/sql-query-questions-answers-for-practice/.
So when I hover the column name it provides "Invalid column name 'FIRST NAME'" and the rest of the column gives the same error message
Another problem is when I try to execute the code, it gives:
Msg 208, Level 16, State 1, Line 17 Invalid object name 'Worker'.
Thanks.
Upvotes: 1
Views: 2852
Reputation: 632
You are passing invalid datetime during the insert. It should be like as below:
INSERT INTO Worker
(WORKER_ID, FIRST_NAME, LAST_NAME, SALARY, JOINING_DATE, DEPARTMENT) VALUES
(001, 'Monika', 'Arora', 100000, '2000-02-14 09:00:00', 'HR')
Upvotes: 0
Reputation: 43626
You have a DROP
statement before the insert. That's why you get an warning that the column is missing.
You may want to move the DROP
statement before the CREATE
one, or even use the new syntax DROP TABLE IF EXISTS ...
if it is available in your edition.
Upvotes: 1