Question:
I need computer SQL coding help?
Miriam
2013-12-03 15:07:07 UTC
So I am learning about SQL in class and had to make a table with data given in Aptana Studio. When i was done I inserted my code into SQL fiddle to look for errors and I seem to have multiple, but i am confused on how to fix them. Any suggestions or corrections??
My code:

CREATE TABLE Nations (
Name varchar(20) NOT NULL,
Domain varchar(3),
Capital varchar(20),
Latitude int,
N_S char(1),
Longitude int,
E_W char(1),
Interest varchar(20),
PRIMARY KEY (Name)

);

SELECT * FROM Nations;

SELECT * FROM Nations
WHERE Interest='Beach';

SELECT * FROM Nations
WHERE (Interest='Beach' AND N_S='S');

SELECT Name FROM Nations;

SELECT Name,Capital,Interest FROM Nations
WHERE Interest='History';

SELECT Name,Latitude FROM Nations
ORDER BY Latitude DESC;

SELECT Name,Latitude FROM Nations
WHERE Interest= 'Art';
ORDER BY Latitude DESC;

INSERT INTO Nations VALUES ('Australia', 'AU', 'Canberra', 37, 'S', 148, 'E', 'Beach')
INSERT INTO Nations VALUES ('Bahamas', 'BS', 'Nassau', 25, 'N', 78, 'W', 'Beach')
INSERT INTO Nations VALUES ('Barbados', 'BB', 'Bridgetown', 13, 'N', 59, 'W', 'Beach')
INSERT INTO Nations VALUES ('Belize', 'BZ', 'Belmopan', 17, 'N', 89, 'W', 'Beach')
INSERT INTO Nations VALUES ('Bermuda', 'BM', 'Hamilton', 32, 'N', 64, 'W', 'Beach')

SELECT COUNT(*) FROM Nations
WHERE Interest = 'History';
INSERT INTO Nations VALUES ('Australia', 'AU', 'Canberra', 37, 'S', 148, 'E', 'Beach');
SELECT * FROM Nations;
WHERE (N_S = 'S' AND Interest = 'Beach');
SELECT Name, DOMAIN FROM Nations
WHERE Interest = 'Kabuki';
SELECT * FROM Nations ORDER BY Name;
SELECT Name, Interest FROM Nations
ORDER BY Interest DESC;

INSERT INTO Nations VALUES ('Bahamas', 'BS', 'Nassau', 25, 'N', 78, 'W', 'Beach')
INSERT INTO Nations VALUES ('Barbados','BB', 'Bridgetown', 13, 'N', 59, 'W', 'Beach')
INSERT INTO Nations VALUES ('Belize', 'BZ', 'Belmopan', 17, 'N', 89, 'W', 'Beach')
INSERT INTO Nations VALUES ('Bermuda', 'BM', 'Hamilton', 32, 'N', 64, 'W', 'Beach')
INSERT INTO Nations VALUES ('Nauru', 'NR','Beach')
INSERT INTO Nations VALUES ('Nepal', 'NP','Mountains')
INSERT INTO Nations VALUES ('Netherlands', 'NL','Canals')
INSERT INTO Nations VALUES ('New Caledonia', 'NC','Beach')
INSERT INTO Nations VALUES ('New Zealand', 'NZ','Adventure')
Three answers:
Yoda
2013-12-05 13:24:27 UTC
This looks like pretty standard SQL (not Database specific), but I noticed your create and select statements use the semicolon as the statement terminator. If you had tried that in Sybase, for example, I think it would have puked.



So, what appears to be the simple problem is a lack of semicolons following the insert statements. That appears to be the one inconsistency in what otherwise looks to be very basic SQL/DDL.
Jeff P
2013-12-03 18:16:10 UTC
Whenever you run queries that fail, the database server will always give you an error number and message. Look at the error message carefully and more than likely you'll find out where your error is. I'm not going to copy and paste all of this--you need to tell us what error you're getting and what you tried to fix it.
Bugsy
2013-12-03 15:41:29 UTC
Run your create table script, by itself. It looks correct



Then run you Inserts, they look correct. If something fails, run each one individually until you find the bad script.



Then run your selects statements



Don't try to run them all at once. You can do this, it is just problematic


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...