0

Step 1: create a new database

CREATE DATABASE MyfirstDatabase;

Step 2:

USE MyFirstDatabase

Step 3 create an employee table inside MyFirstDatabase:

CREATE TABLE Employee
(
    EmpID nvarchar(50), 
    Name nvarchar(50),
    DOB Date
);

Step 4: insert values into Employee table:

INSERT INTO Employee 
VALUES ('E01', 'John', '3 November 2000');

INSERT INTO Employee 
VALUES ('E02', 'Kelly', '24 November 2000');

DROP DATABASE MyfirstDatabase
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
  • Another problem is that your DOB values are in the wrong format. '3 November 2000' should be '2000-11-03'. – kmoser Mar 19 '22 at 04:36
  • Before inserting, try executing SELECT query i.e. SELECT * FROM Employee to see whether the table exists or not. I suspect its happening due to the incorrect scheme owner or permission. – Kundan Singh Chouhan Mar 19 '22 at 04:55
  • While I agree the date string format should be yyyy-mm-dd, that exact code works as is here http://sqlfiddle.com/#!18/62febe/1 – SOS Mar 19 '22 at 06:00
  • 1
    @SOS It works with MS SQL Server, not MySQL. The question was only tagged "SQL", not with a specific RDBMS, so it's not clear which is correct. – kmoser Mar 19 '22 at 16:17
  • @kmoser - True it's not tagged. Though I don't think MySQL has data type `nvarchar`. – SOS Mar 20 '22 at 19:13
  • 1
    @SOS [MySQL supports `nvarchar`](https://stackoverflow.com/a/13922851/378779) – kmoser Mar 20 '22 at 21:16
  • @kmoser - Duh! Thanks for that. Don't know how I missed it (TIL) – SOS Mar 20 '22 at 21:20

1 Answers1

1

Try this:

After creating databse MyFirstDatabase and table Employee

USE MyFirstDatabase;

INSERT INTO Employee VALUES
('E01','John','2000-11-03');

INSERT INTO Employee VALUES
('E02','Kelly','2000-11-24');

Date format should be in yyyy-MM-dd format

Nayanish Damania
  • 542
  • 5
  • 13