Welcome Guest ( Log In | Register )



2 Pages V   1 2 >  
Reply to this topicStart new topic
> Updating A Database's Tables
nightfox
post Jun 1 2006, 01:45 AM
Post #1


NiGHTFoX - Hiding in the dark
Group Icon

Group: Members
Posts: 680
Joined: 3-April 05
Member No.: 3,584



Is there an "easy" way to update a database's tables? Like for instance, I have my own custom-coded member login system. Whenever I add a new feature that needs a database, I manually have to download, update and upload the database. Is there an easy way I can do this?

THANKS!!!

[N]F
Go to the top of the page
 
+Quote Post
yordan
post Jun 1 2006, 09:40 AM
Post #2


Way Out Of Control - You need a life :)
Group Icon

Group: [MODERATOR]
Posts: 2,042
Joined: 16-August 05
Member No.: 7,896



Usually, it's rather easy to update a table in a database.
The syntax is something like "insert into MYTABLE values SOMETHING, SOMETHING_ELSE, ..."
Was this your exact question ?
Go to the top of the page
 
+Quote Post
Hercco
post Jun 1 2006, 01:25 PM
Post #3


Super Member
Group Icon

Group: Members
Posts: 595
Joined: 4-September 04
Member No.: 228



What Yordan posted was inserting a record to the database and I don't think Nightfox is after that.

You are looking to change the tables structure right? Updating in database world usually means updating a single record which is done with SQL command beginning with UPDATE keyword or command or whatever.

You can do all possible operations to a database with queries. Sometimes certain features might be limited (for example dropping databases might not be allowed from PHP scripts and so on) but usually you should be able to change the structure. Well provided that the user has create rights.

Basically how you do it is use ALTER TABLE query. For example you can add column with query like this "ALTER TABLE tablename ADD column type". Naturally the syntax is exactly the same as for creating tables so you can everything here you can do there. You can drop columns with "ALTER TABLE tablename DROP COLUMN columnname".

It is also possible to rename and change datatypes for columns, but unless I'm completely mistaken the syntax varies from DBMS to DBMS. MySQL uses CHANGE "ALTER TABLE tablename CHANGE oldname newname type". Notice that you can change the type here. To just change the type keep the name same.

I have a vague memory that Oracle uses RENAME... I could be wrong though.



I hope this answers your question.
Go to the top of the page
 
+Quote Post
yordan
post Jun 1 2006, 08:44 PM
Post #4


Way Out Of Control - You need a life :)
Group Icon

Group: [MODERATOR]
Posts: 2,042
Joined: 16-August 05
Member No.: 7,896



Nicely answered, Hercco.
I must confess that i was confused by the topic title, I understood the " Updating A Database's Tables" by updating some rows in a table, which is different from insert but thas nothing to do with the ALTER TABLE notion.
Sorry again
Yordan

This post has been edited by yordan: Jun 1 2006, 08:45 PM
Go to the top of the page
 
+Quote Post
nightfox
post Jun 2 2006, 11:08 PM
Post #5


NiGHTFoX - Hiding in the dark
Group Icon

Group: Members
Posts: 680
Joined: 3-April 05
Member No.: 3,584



QUOTE(Hercco @ Jun 1 2006, 09:25 AM) *

What Yordan posted was inserting a record to the database and I don't think Nightfox is after that.

You are looking to change the tables structure right? Updating in database world usually means updating a single record which is done with SQL command beginning with UPDATE keyword or command or whatever.

Thanks!! I'll look into all of that. It does look like what I'm after. I use MySQL, not Oracle. But thanks again!!

[N]F
Go to the top of the page
 
+Quote Post
Chesso
post Jun 3 2006, 02:20 AM
Post #6


Teh Coder
Group Icon

Group: Members
Posts: 1,053
Joined: 18-April 06
From: Australia
Member No.: 12,833



I'm pretty sure most if not all database software accepts pretty much the exact same syntax or close to it. I would say UPDATE is what you are looking for, it basically let's you change a field in a table to my knowledge to say update a int value incrementaly and such.

INSERT would allow you to insert a new field in the table or record either way, by id or if the table has an auto_incremental primary key then it would do it automatically.

I don't know of ALTER though? it sounds like it does the same thing as UPDATE? (Either way updating or altering your'e changing the original so what would be the difference between the two? there shouldn't be....)
Go to the top of the page
 
+Quote Post
miCRoSCoPiC^eaRt...
post Jun 3 2006, 06:11 AM
Post #7


PsYcheDeLiC dR3aMeR
Group Icon

Group: Admin
Posts: 2,242
Joined: 29-January 05
From: Nakorn Chaisri, Thailand
Member No.: 2,411



Yep - the INSERT and UPDATE syntax is almost same in any SQL Compliant Database...

Chesso: UPDATE and ALTER have diametrically opposite functions - though both names suggest some sort of updating mechanism... UPDATE is used to modify the DATA stored inside a table, whereas ALTER is used to modify the STRUCTURE of the table itself.

Your usual UPDATE syntax (for MySQL) would be:
SQL
UPDATE tableName SET Field1 = 'newvalue1', Field2 = 'newvalue2', ...;


ALTER, as shown by Hercco allows you to modify the Column names as well as their data types in a particular table... Say in the above table, Field1 was VARCHAR and Field2 was DOUBLE... I want to swap the data types and change the name of Field2 to Field3
SQL
ALTER TABLE tableName CHANGE Field1 Field1 DOUBLE;
ALTER TABLE tableName CHANGE Field2 Field3 VARCHAR(x);
Go to the top of the page
 
+Quote Post
Chesso
post Jun 3 2006, 10:07 AM
Post #8


Teh Coder
Group Icon

Group: Members
Posts: 1,053
Joined: 18-April 06
From: Australia
Member No.: 12,833



Ahhh so one changes the data stored and the other just changes the type of data stored.
Go to the top of the page
 
+Quote Post
yordan
post Jun 3 2006, 02:46 PM
Post #9


Way Out Of Control - You need a life :)
Group Icon

Group: [MODERATOR]
Posts: 2,042
Joined: 16-August 05
Member No.: 7,896



Yes, in all SQL RDBMS the syntax is very similar.
CREATE TABLE to create a table
ALTER TABLE to change the table structure
INSERT INTO table to add rows
etc...
Very few differences between Oracle, Ingres, Informix, Mysql, PostGre.
Of course, things are easier if you use integrated scripts like the ones in cpanel, but sometimes you have to understand basics, or at least know the terminology.

This post has been edited by yordan: Jun 4 2006, 10:40 PM
Go to the top of the page
 
+Quote Post
vhortex
post Jun 5 2006, 12:59 PM
Post #10


Guilty Until Proven Innocent
Group Icon

Group: Members
Posts: 372
Joined: 13-April 05
Member No.: 3,937



QUOTE(nightfox @ Jun 3 2006, 07:08 AM) *

Thanks!! I'll look into all of that. It does look like what I'm after. I use MySQL, not Oracle. But thanks again!!

[N]F


Oracle's SQL is the same as mySQL with just some addons and optiomations..
on the other hand, for a small scale bussiness which need an Oracle functionality,
mySQL 5 is a nice thing to start with..

As long as it uses SQL and a compliant, the database controls are the same..
Go to the top of the page
 
+Quote Post

2 Pages V   1 2 >
Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. Free Databases(14)
  2. The Best Database(41)
  3. Need Advice On Creating Online Music Database(6)
  4. Recover Tables From A MySQL .frm File(8)
  5. Hosting A Server On Database(6)
  6. Remote Databases(4)
  7. Migrating Databases(2)
  8. Creating Databases(4)
  9. Unexpected Database Crashes(0)
  10. Combining Databases(4)
  11. Creating Tables In MySQL On Home Comp(8)
  12. User Priveileges Vs. Tables Vs Rows(1)
  13. What Is A Database How Do I Use One?(7)
  14. MySQL, Multiple Tables(24)
  15. Linking Two Tables(12)
  1. How To Setup SMF Databases?(4)
  2. Copy Databases In phpMyAdmin(3)
  3. Can You Make Your Own MySQL Databases?(7)
  4. Ms Databases(6)
  5. (help With Sql And Php)retrive Datas From Realted Tables And Display Them!(4)
  6. How Do You Make Large Databases?(14)
  7. Examining Databases At A Whole Glance(7)
  8. All About Databases(3)
  9. Script Tables On Sql Server Compact(0)
  10. Mysql Problem(1)
  11. Free Graphical Tools For Databases(7)
  12. Databases(2)
  13. Mysql Multiple Tables(1)


 



- Lo-Fi Version Time is now: 11th October 2008 - 09:59 AM