Jump to content

Adding New Column In Table Using Sql


anggwaponi

Recommended Posts

hi all :)i have follow some tutorial lessons in sql and i arrived in a stage when my curiosity invigorates my enthusiasms to farther hone my skills but not just practicing but also inquiring :) in the table i created (which i name PRACTICE_SQL101) ... i want to add a column between an already existing 2-columns ::(how can i possibly do it [i want it to be between the column City and Country to be names as Zip Code] ... what sort of commands or syntax in sql will i use then? likewise, i want the Zip Code to accept only numbers only :-\the header of my table looks like this:P_Id LName FName Address City Countrythanks a lot of any valuable suggestions 8)cheers! :)p.s. hello Moderators ... please allow me sometime to change my signature. thanks :)

Link to comment
Share on other sites

Try this:ALTER TABLE `PRACTICE_SQL101` ADD `zipcode` INT AFTER `city`I used the INT type to restrict your field to numbers. An unsigned INT goes up to 4294967295, more than enough for a zip+4. But if you try to insert something not an integer into the zipcode field, don't expect a big error or warning or something. In my MySql implementation, inserting a string just results in inserting an INT with value 0. If there's a way to validate the value before inserting it, I don't know. Someone else might.LURKERS: Be advised OP is not interfacing through PHP. AFAIK, OP is using pure SQL. Any way to bounce bad data before inserting?

Link to comment
Share on other sites

Try this:ALTER TABLE `PRACTICE_SQL101` ADD `zipcode` INT AFTER `city`I used the INT type to restrict your field to numbers. An unsigned INT goes up to 4294967295, more than enough for a zip+4. But if you try to insert something not an integer into the zipcode field, don't expect a big error or warning or something. In my MySql implementation, inserting a string just results in inserting an INT with value 0. If there's a way to validate the value before inserting it, I don't know. Someone else might.LURKERS: Be advised OP is not interfacing through PHP. AFAIK, OP is using pure SQL. Any way to bounce bad data before inserting?
hello Dad Deirdre :) and looks like yur the best Dad in the whole wide world then ... :) thanks really for yur very nice input ... the table i created now looks good (though their are still lots of things to be improve but they're manageable ... of course, with yur guidance).again, thanks really.cheers! :)
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...