Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Website Design/Showcase (http://www.chiefdelphi.com/forums/forumdisplay.php?f=64)
-   -   Need Help with SQL (http://www.chiefdelphi.com/forums/showthread.php?t=26199)

Tom Bottiglieri 28-02-2004 14:41

Need Help with SQL
 
hi, im trying to set up a SQL database for our teams scouting needs. I have NO idea how to do any of this stuff. I have the SQL server, and i know how to set up tables and stuff, but i have no idea how to enter info or access it.

Mr. Ivey 28-02-2004 16:56

Re: Need Help with SQL
 
for access, just using the command line you type something like this
SELECT t.team_number=384, d.drive_type=hyper;
FROM team t, drive d;
if you don't have multiple tables, and the info is just in the rows it goes like this
SELECT team_number=384, drive_type=hyper;
FROM team;
for entering info, i will get back to you, i need to find my Oracle 9i and SQL notes from last year in OIA. But I will let you know.
ivey

Found my notes, you need to use the INSERT INTO command, and then give the colums to insert info in, and then the corresponding data. After you type the inital command you need to put the name of the table, and then after that the schema. The whole thing looks like this:
INSERT INTO RoboInfo.SchemaIvey (drive_train, wheels) VALUES (hyper, MonsterTruck);

If you have any more questions search for information on Data Manipulation Language, or DML in SQL. Here is also a tutorial that helped me get through my Oracle class last year: SQL Help and Tutorial

deltacoder1020 28-02-2004 18:16

Re: Need Help with SQL
 
in all of these examples, "..." just means you can have as many fields as you want.

basic insert:
Code:

INSERT INTO table (field1, field2, ...) VALUES ("field1data","field2data",...);
another way to insert:
Code:

INSERT INTO table SET field1="field1data", field2="field2data", ...;
basic retrieval of results:
Code:

SELECT * FROM table;
only retrieve certain fields:
Code:

SELECT field1,field2,... FROM table;
selective retrieval of results:
Code:

SELECT * FROM table WHERE field3="field3value";
ordering the results retrieved:
Code:

SELECT * FROM table ORDER BY field3;
only retrieve the first few results (up to the number specified):
Code:

SELECT * FROM table LIMIT number;
deleting all rows:
Code:

DELETE FROM table;
deleting certain rows:
Code:

DELETE FROM table WHERE field1="field1data";
you can combine just about any of the modifiers above, for example,
Code:

SELECT userid,username FROM users WHERE usergroup="test" ORDER BY userid LIMIT 30;
would give me the username and userid of the first 30 people in the users table whose usergroup is "test", ordered by their userids.

Raven_Writer 28-02-2004 19:27

Re: Need Help with SQL
 
For SQL tutorials (and a slew of others), W3Schools.org is the site to goto.

steven114 28-02-2004 22:20

Re: Need Help with SQL
 
If you have PHP available, I would suggest using PHPMyAdmin. It makes using mySQL so much easier.

(I am assuming that you are using mySQL, you didn't specify)

Tom Bottiglieri 28-02-2004 22:51

Re: Need Help with SQL
 
yeah i have PHPmyAdmin and mySQL. Being a web design noob, i still cant figure it out.

KevinB 29-02-2004 02:26

Re: Need Help with SQL
 
www.webmonkey.com has some pretty good PHP+MySQL tutorials also.

pedro 29-02-2004 17:54

Re: Need Help with SQL
 
I think your problem lies in connecting to the database using PHP or whatever else you may be using. I don't know much PHP, but i'm guessing it shouldn't be more than 10 lines of code to set up a connection, and then use some of the SQL statements that were mentioned above.

Of course if it were up to me, I wouldn't use PHP in the first place (ColdFusion is way more straight forward), but that's another topic...

Raven_Writer 29-02-2004 18:51

Re: Need Help with SQL
 
Quote:

Originally Posted by pedro
I think your problem lies in connecting to the database using PHP or whatever else you may be using. I don't know much PHP, but i'm guessing it shouldn't be more than 10 lines of code to set up a connection, and then use some of the SQL statements that were mentioned above.

Of course if it were up to me, I wouldn't use PHP in the first place (ColdFusion is way more straight forward), but that's another topic...

Just for the record, it depends on how you'd like to connect to the db on how many lines it'd take.

Here's the smallest way to connect to a db IMO (incase you are having trouble with connecting):
PHP Code:

<?php
$db 
mysql_connect_db("localhost""fred""loves_wilma");
 
mysql_connect($db);
 
mysql_close();
?>

It may not be totally correct syntax, but that's because I haven't touched PHP in a while

deltacoder1020 29-02-2004 20:45

Re: Need Help with SQL
 
Quote:

Originally Posted by Raven_Writer
Just for the record, it depends on how you'd like to connect to the db on how many lines it'd take.

Here's the smallest way to connect to a db IMO (incase you are having trouble with connecting):
PHP Code:

<?php
$db 
mysql_connect_db("localhost""fred""loves_wilma");
 
mysql_connect($db);
 
mysql_close();
?>

It may not be totally correct syntax, but that's because I haven't touched PHP in a while

PHP Code:

<?php

mysql_connect
("dbhost","dbuser","dbpass") or die("could not connect to db";
mysql_select_db("dbname") or die("could not select database");
$result mysql_query("query string") or die("could not query database");

//process data

?>

(php automatically closes the database connection at the end of the script)

Raven_Writer 01-03-2004 15:49

Re: Need Help with SQL
 
Heh, thanks. I thought I didn't do the coding right. But yea, that example works the best. (IMO though, it might be safer to close the connection on your own anyways, incase PHP forgets to do that)


All times are GMT -5. The time now is 14:06.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi