In my database, i have payment table paymentid, amount, duedate, approvalcode, status, transactionid etc.
payment table has already 15 columns.
if i want to store tip, tax, disount against paymentid.
what is better
create new paymentdetails table with one to one relationship
or
add columns in same payment table?
pls help.
payment table has almost more than 50000 records. so what is really good for database.
Here are two scenarios I see for creating a table based on an existing one: create a summary table from detail table - faster read of data based on precalculated results; secondly, reliability would be high as calculated fields in summary can be traced back to source.
The ALTER TABLE statement is used to add, delete, or modify columns in an existing table. The ALTER TABLE statement is also used to add and drop various constraints on an existing table.
It saves space and its flexible. Realistically, you cant really put everything in one table.
A copy of an existing table can be created using a combination of the CREATE TABLE statement and the SELECT statement. The new table has the same column definitions. All columns or specific columns can be selected.
With such small tables I don't see a reason for not putting the new columns in the existing table.
You would do that if
Generally, I work on the premise that attributes of something/entity/object should be stored against the something/entity/object. Typically, I only split out into a new table when there is a one to many relationship - so an attribute that has multiple values (e.g. person and qualifications held)
I would add them to the payment table - although perhaps you have an order table they would more suitably relate to?
You will need to keep in mind whether you will need indexes over these columns though - if you add indexes, you could overburden your table and deteriorate performance but you would probably only add indexes in instances where you used the columns in joins and they don't sound like the sort of thing you would need to join on.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With