0

i created this table

create table courses (
cid int primary key not null,
cname varchar(25) )

and when i tried to insert any thing like that

insert into courses values (1,name)

i have this error

insert into courses values (1,`ahmed`)

Error Code: 1054. Champ 'ahmed' inconnu dans field list 0.000 sec

when i try to add only cid it's ok , i removed the table and created it twice and the same problem

what is the wrong thing here?

1
  • 1
    insert into courses values (1,'ahmed') : try this Commented Dec 24, 2015 at 11:58

2 Answers 2

2

You need to delimit your varchar values with single quotes (').

Try the following instead:

insert into courses values (1,'ahmed');

Numerics can be passed without the single quotes, however any char or varchar derived types need the single quotes. Look up datatypes for SQL for further information.

Sign up to request clarification or add additional context in comments.

1 Comment

Try changing your statement, you are using the back-tick ` instead of a single quote ', copy the statement directly from my answer and try executing it. I believe mysql uses back-tick to delimit objects ( tables, columns, etc...) single quotes are used to delimit values.
1

Put Single quote (') for string values

Try this:

INSERT INTO courses (cid, cname)
VALUES (1, 'ahmed');

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.