|
|
|
|
![]() ![]() |
Jun 1 2006, 01:45 AM
Post
#1
|
|
|
NiGHTFoX - Hiding in the dark 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 |
|
|
|
Jun 1 2006, 09:40 AM
Post
#2
|
|
|
Way Out Of Control - You need a life :) 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 ? |
|
|
|
Jun 1 2006, 01:25 PM
Post
#3
|
|
|
Super Member 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. |
|
|
|
Jun 1 2006, 08:44 PM
Post
#4
|
|
|
Way Out Of Control - You need a life :) 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 |
|
|
|
Jun 2 2006, 11:08 PM
Post
#5
|
|
|
NiGHTFoX - Hiding in the dark Group: Members Posts: 680 Joined: 3-April 05 Member No.: 3,584 |
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 |
|
|
|
Jun 3 2006, 02:20 AM
Post
#6
|
|
|
Teh Coder 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....) |
|
|
|
Jun 3 2006, 06:11 AM
Post
#7
|
|
|
PsYcheDeLiC dR3aMeR 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); |
|
|
|
Jun 3 2006, 10:07 AM
Post
#8
|
|
|
Teh Coder 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.
|
|
|
|
Jun 3 2006, 02:46 PM
Post
#9
|
|
|
Way Out Of Control - You need a life :) 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 |
|
|
|
Jun 5 2006, 12:59 PM
Post
#10
|
|
|
Guilty Until Proven Innocent Group: Members Posts: 372 Joined: 13-April 05 Member No.: 3,937 |
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.. |
|
|
|
![]() ![]() |
Similar Topics
|
Lo-Fi Version | Time is now: 11th October 2008 - 09:59 AM |