sql database, and table set up, can some one help me see what the issue here is

Fragoso, Ariana M 26 Reputation points
2022-05-19T17:36:24.397+00:00

CREATE DATABASE TableInsert;

CREATE TABLE employee (
PersonID int,
FirstName varchar(255),
LastName varchar(255),
Age int,
HiredDate varchar(255),
);
Insert into tbl_employee(Fristname, Last name ,age, HiredDate)
values( ‘Alan’, ‘Palmer’, 32 , ‘2019-12-15),
( 'Susan', ‘Shepard’, 28 , ‘2015-07-21'),
( 'Justin', 'Ward', 43 , '2017-08-24'),

Developer technologies Transact-SQL
SQL Server Other
{count} votes

Accepted answer
  1. Naomi Nosonovsky 8,431 Reputation points
    2022-05-20T01:52:50.133+00:00

    I just tried the script (originally didn't test). This works fine in SQL Server:

    CREATE DATABASE TableInsert;
    GO
    USE TableInsert;
     CREATE TABLE employee (
     PersonID int identity(1,1) primary key,
     FirstName varchar(30) NULL,
     LastName varchar(50) NULL,
     Age int,
     HiredDate date
     );
     Insert into employee(Firstname, LastName, age, HiredDate)
     values( 'Alan', 'Palmer', 32 , '2019-12-15'),
     ( 'Susan', 'Shepard', 28 , '2015-07-21'),
     ( 'Justin', 'Ward', 43 , '2017-08-24') ;
    
     SELECT * FROM employee;
    

    Few observations: Note that I changed the types and I used date type for the HiredDate. It is always a good idea to use proper SQL data type in order to avoid bad data. Now, there is a debate if we want to use singular or plural for the table name. I would probably use plural. I also specified that Id colum is a primary key and it's incremented automatically.

    1 person found this answer helpful.

2 additional answers

Sort by: Most helpful
  1. Naomi Nosonovsky 8,431 Reputation points
    2022-05-19T18:26:03.817+00:00

    Try fiew corrections (not tested, but I can see these mistakes):

    CREATE DATABASE TableInsert;
    
    CREATE TABLE employee (
    PersonID int identity(1,1) primary key,
    FirstName varchar(30),
    LastName varchar(50),
    Age int,
    HiredDate date
    );
    Insert into tbl_employee(Fristname, LastName ,age, HiredDate)
    values( 'Alan', 'Palmer', 32 , '2019-12-15'),
    ( 'Susan', 'Shepard', 28 , '2015-07-21'),
    ( 'Justin', 'Ward', 43 , '2017-08-24') ;
    

  2. Bert Zhou-msft 3,436 Reputation points
    2022-05-20T02:13:53.057+00:00

    Hi,@Fragoso, Ariana M

    Welcome to Microsoft T-SQL Q&A Forum!

    A simple method is to add '' directly. SQL will treat it as a string, or you can use Ctrl + 0 to implement it.
    First of all , please make sure that the database you are using is SQL Server , the syntax will be different if you are using other databases . like this:

     select @@version  
    

    From the code you posted, you have several basic syntax errors:

    1) Although PersonID is defined, but you do not assign a value when inserting data into the table, naomi's identity self-increment can solve this problem;

    2) Carefully observe, you use the wrong reference symbols, I guess it is the problem of your input method, such as ' and ' are different;

    3) The last field cannot be added when the table is created, I think you should know why.

    Hope it helps you.

    Best regards,
    Bert Zhou


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our Documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.