Database Newbie question, about my SQL statemnt

DeadSeaSquirrels

Senior member
Jul 30, 2001
515
0
0
I want to do some simple stuff, just entering some data into a database. I am using phpmyadmin provided for by my hosting company.

I am using the following line.

INSERT INTO USERS (First Name) VALUE ('Mal');

I am positive everything is spelled correctly, I do in fact have a field called First name. But it keeps on giving me an error message, and the message is vague just saying something about how there is an error near "Name." At first I thought it might be because field names can't have spaces, but I looked that up and that is not true. So I don't understand at all.

Also I am using TWANG to convert some excel sheets to SQL scripts. And I used one script that TWANG created for me, and it worked fine, but then this one (this one is actually apart of a much larger script), doesn't work. Can somebody give me a heads up as to what it might be.

P.S. I tried putting "First Name" in double quotes, single quotes, and as is. nothing works.
 

Mitzi

Diamond Member
Aug 22, 2001
3,775
1
76
Originally posted by: DeadSeaSquirrels


INSERT INTO USERS (First Name) VALUE ('Mal');

INSERT INTO USERS (First Name) VALUES ('Mal');

Put an 'S' on values



 

bunker

Lifer
Apr 23, 2001
10,578
0
71
Also you may have to put quotes around 'First Name' because there is a space in the name.

To make life easier on you either don't use spaces in table/column names or use an underscore instead of a space.
 

DeadSeaSquirrels

Senior member
Jul 30, 2001
515
0
0
The "s" was my fault, the original SQL line had an S for ValueS, but I guessed I cropped it when I copied it over. Anyway, as the bottom of my post mentioned I've tried it with both single quotes and double quotes, neither have worked. I remember checking with the SQL manual and they said that spaces are allowed for field names. Which is why I'm so confused.
 

bunker

Lifer
Apr 23, 2001
10,578
0
71
Originally posted by: DeadSeaSquirrels
The "s" was my fault, the original SQL line had an S for ValueS, but I guessed I cropped it when I copied it over. Anyway, as the bottom of my post mentioned I've tried it with both single quotes and double quotes, neither have worked. I remember checking with the SQL manual and they said that spaces are allowed for field names. Which is why I'm so confused.

Yes, you are allowed to use spaces for table names, but when you call that name in a select or other statement you have to put it in quotes (at lease for MS SQL)
 

DeadSeaSquirrels

Senior member
Jul 30, 2001
515
0
0
Well I guess I have no idea what is going on then, because I put the field name in double quotes and in single quotes neither one working. It is on a mySQL server I believe.
 

bunker

Lifer
Apr 23, 2001
10,578
0
71
I just looked at the MySQL documentation (bookmark it and use it!)

INSERT INTO USERS ('mal');

That's it. You don't specify the column in an insert statement, only an UPDATE statement.

You have to account for each column in the table though, so assuming you have 3 columns in the USERS table (First Name, Last Name, Address) It would look like this:

INSERT INTO USERS ('mal',,);

You need the commas there.
 

DeadSeaSquirrels

Senior member
Jul 30, 2001
515
0
0
Thanks, I'll look it up myself. But before I look it up, I am going to have to say that I think that is highly unlikely, and this is why. First I used TWANG to generate the script, the scripts that TWANG generate all have the original INSERT USERS (field names) part of it. I used one of the scripts that TWANG generated already and it worked. Which is another reason it is weird (but in that case, some weird buggy things were happening anyway).

Also, besides the fact that it worked, it is unlikely, I think, that a company would release a application that is so fundamentally screwed up. Free yes, but the reputation of their company rests on that.

Second, when I use phpmyAdmin through my hosting company, and can insert items using the phpmyadmin interface, and after inserting an item, the script that did the inserting shows up at the top. And when I checked it out it does indeed have the original INSERT USERS (field name) part. Again I'll take a look see, but if that is the case, that is just really weird.
 

bunker

Lifer
Apr 23, 2001
10,578
0
71
Originally posted by: DeadSeaSquirrels
Thanks, I'll look it up myself. But before I look it up, I am going to have to say that I think that is highly unlikely, and this is why. First I used TWANG to generate the script, the scripts that TWANG generate all have the original INSERT USERS (field names) part of it. I used one of the scripts that TWANG generated already and it worked. Which is another reason it is weird (but in that case, some weird buggy things were happening anyway).

Also, besides the fact that it worked, it is unlikely, I think, that a company would release a application that is so fundamentally screwed up. Free yes, but the reputation of their company rests on that.

Second, when I use phpmyAdmin through my hosting company, and can insert items using the phpmyadmin interface, and after inserting an item, the script that did the inserting shows up at the top. And when I checked it out it does indeed have the original INSERT USERS (field name) part. Again I'll take a look see, but if that is the case, that is just really weird.

Well, you go ahead and use you're twang.

I'll stop checking in this thread.
 

Descartes

Lifer
Oct 10, 1999
13,968
2
0
Originally posted by: bunker
I just looked at the MySQL documentation (bookmark it and use it!)

INSERT INTO USERS ('mal');

That's it. You don't specify the column in an insert statement, only an UPDATE statement.

You have to account for each column in the table though, so assuming you have 3 columns in the USERS table (First Name, Last Name, Address) It would look like this:

INSERT INTO USERS ('mal',,);

You need the commas there.

In ANSI SQL, and every SQL dialect I've ever used, the specification of columns is optional; if left off, it uses defaults to the schema of the table in the insert. This is from the MySQL documentation:

INSERT [LOW_PRIORITY | DELAYED] [IGNORE]
[INTO] tbl_name [(col_name,...)]
VALUES ((expression | DEFAULT),...),(...),...
[ ON DUPLICATE KEY UPDATE col_name=expression, ... ]
or INSERT [LOW_PRIORITY | DELAYED] [IGNORE]
[INTO] tbl_name [(col_name,...)]
SELECT ...
or INSERT [LOW_PRIORITY | DELAYED] [IGNORE]
[INTO] tbl_name
SET col_name=(expression | DEFAULT), ...
[ ON DUPLICATE KEY UPDATE col_name=expression, ... ]
 

DeadSeaSquirrels

Senior member
Jul 30, 2001
515
0
0
Descartes, I'm not sure what you mean by that. Are you saying that there is no standard? Or that I shouldn't be able to put spaces as column names? Well I see the column names with spaces in there...whether mySQL understands what is going on, is another questions.

Somebody also suggested doing this
INSERT INTO table_name (table_name.first name) VALUES ('Mal')

Or putting quotes around the word "first name", I've tried all of that, single quotes, double quotes, no quotes. Still nothing. The manual says I can use spaces, and at this point it is easier just to take the spaces out, but I just want to know, for my own sanity sake.
 

calpha

Golden Member
Mar 7, 2001
1,287
0
0
Well, the answer isn't quotes.

It's the ` mark. I just tested this statement from the mysql command line:

mysql> insert into mytable (`my name`) values ('testing');
Query OK, 1 row affected (0.00 sec)

mysql> select * from `mytable`;
+---------+
| my name |
+---------+
| testing |
+---------+
1 row in set (0.00 sec)
 

DeadSeaSquirrels

Senior member
Jul 30, 2001
515
0
0
Thanks, I just tried it and indeed it is the tick `

I thought I had tried that before, because I suspected that it might be something silly like that, and I did try it, but I guess at that point I was trying so many different things at once, that something else was screwed up. I guess I did not use a vigorous scientific method - and I was punished.

But thanks again, I will spread the gospel now.
 
sale-70-410-exam    | Exam-200-125-pdf    | we-sale-70-410-exam    | hot-sale-70-410-exam    | Latest-exam-700-603-Dumps    | Dumps-98-363-exams-date    | Certs-200-125-date    | Dumps-300-075-exams-date    | hot-sale-book-C8010-726-book    | Hot-Sale-200-310-Exam    | Exam-Description-200-310-dumps?    | hot-sale-book-200-125-book    | Latest-Updated-300-209-Exam    | Dumps-210-260-exams-date    | Download-200-125-Exam-PDF    | Exam-Description-300-101-dumps    | Certs-300-101-date    | Hot-Sale-300-075-Exam    | Latest-exam-200-125-Dumps    | Exam-Description-200-125-dumps    | Latest-Updated-300-075-Exam    | hot-sale-book-210-260-book    | Dumps-200-901-exams-date    | Certs-200-901-date    | Latest-exam-1Z0-062-Dumps    | Hot-Sale-1Z0-062-Exam    | Certs-CSSLP-date    | 100%-Pass-70-383-Exams    | Latest-JN0-360-real-exam-questions    | 100%-Pass-4A0-100-Real-Exam-Questions    | Dumps-300-135-exams-date    | Passed-200-105-Tech-Exams    | Latest-Updated-200-310-Exam    | Download-300-070-Exam-PDF    | Hot-Sale-JN0-360-Exam    | 100%-Pass-JN0-360-Exams    | 100%-Pass-JN0-360-Real-Exam-Questions    | Dumps-JN0-360-exams-date    | Exam-Description-1Z0-876-dumps    | Latest-exam-1Z0-876-Dumps    | Dumps-HPE0-Y53-exams-date    | 2017-Latest-HPE0-Y53-Exam    | 100%-Pass-HPE0-Y53-Real-Exam-Questions    | Pass-4A0-100-Exam    | Latest-4A0-100-Questions    | Dumps-98-365-exams-date    | 2017-Latest-98-365-Exam    | 100%-Pass-VCS-254-Exams    | 2017-Latest-VCS-273-Exam    | Dumps-200-355-exams-date    | 2017-Latest-300-320-Exam    | Pass-300-101-Exam    | 100%-Pass-300-115-Exams    |
http://www.portvapes.co.uk/    | http://www.portvapes.co.uk/    |