Reputation: 13
I have created a database in MySQL and am trying to insert values into a table called Artist but keep receiving the SQL error in the title. This is the query I am trying to execute
insert Artist (ArtistId, name, genre, social media, G_id)
Values ('911', 'Alessandro Torlonia', 'Ancient Greek/Roman', '', '734')
I have also tried executing INSERT INTO
before my table name and have run out of ideas to make it work. Do I need to update MySQL workbench or any other suggestions?
Upvotes: 1
Views: 1968
Reputation: 222462
The standard insert
syntax goes like:
insert into Artist (ArtistId, name, genre, social_media, G_id)
values (911, 'Alessandro Torlonia', 'Ancient Greek/Roman', NULL, 734)
Notes:
presumably, ArtistId
and G_id
are of a numeric datatype (such as INT
), not strings (VARCHAR
or the-like); if so, I would recommend not surrounding the values with single quotes. Using strings won't raise errors (the database handles the conversion for you under the hood) but it is good practice to use the proper datatype
social media
probably needs an underscore in between; or, if you do have a space in the column name, you need to surround the column name with backticks. Note that I assigned a NULL
value to instead of the empty string; this is usually the preferred way to represent the absence of data (and it is valid for all datatypes, unlike the empty string, that only string-like datatypes support)
Upvotes: 1