SQLTeam.com | Weblogs | Forums

Update query error for new learner


#1

I have been learning sql by sql queries eg. select, union etc.
I am trying to create a database this is the code:

CREATE TABLE Clubs ( ClubID INT NOT NULL, ClubName VARCHAR(50) NOT NULL, PRIMARY KEY (ClubID))
INSERT INTO clubs (ClubID, ClubName) VALUES ('1', 'The Pullman Club');

this is the error:
You have an error in your SQL syntax; syntax to use near 'INSERT INTO clubs (ClubID, ClubName) VALUES ('1', 'The Pullman Club')' at line 2


#2

You're inserting string value into int field. Remove quote chars around fiest field, and you should be good to go.


#3

This is the code I am trying but:
CREATE TABLE Clubs ( ClubID INT NOT NULL, ClubName VARCHAR(50) NOT NULL, PRIMARY KEY (ClubID))
INSERT INTO clubs (ClubID, ClubName) VALUES (1, The Pullman Club);

it says I have
You have an error in my SQL syntax;
for the right syntax to use near 'INSERT INTO clubs (ClubID, ClubName) VALUES (1, The Pullman Club)' at line 2


#4

Now you removed the quotes around the string.
Try this:

INSERT INTO clubs (ClubID, ClubName) VALUES (1, 'The Pullman Club')

#5

You are creating a Table, not database

Don't see any real issue with that. Except as @bitsmed mention using string literal '1' instead of 1. And maybe if your collation is case sensitive, you should do INSERT INTO Clubs and not clubs.

The above query does not have any issue when executing in MS SQL Server. What database are you using ?


#6

Perhaps it needs a statement separator between the CREATE and the INSERT?

(Its a MySQL error - this is a Microsoft SQL Server forum, so you may not find folk here with enough knowledge to help you - as others have said this syntax would work fine on Microsoft SQL Server as it will "silently" convert the string '1' to an integer before storing in your [ClubID] column)


#7

I believe you must end the CREATE statement with a semi-colon:

CREATE TABLE Clubs ( ClubID INT NOT NULL, ClubName VARCHAR(50) NOT NULL, PRIMARY KEY (ClubID)); /added a semi-colon here/
INSERT INTO clubs (ClubID, ClubName) VALUES ('1', 'The Pullman Club');