bfha9p3wbnfa
bfha9p3wbnfa

Reputation: 9

mySQL- add data under single column

h i all, i am working on java app that contains mysql database and everything was fine but now i am stuck... :\ :D

my plan: there are columns and rows :D every column header represent one entity, and number of column headers in database is not constant over time (they may be added). there are no rows at beginning, into rows i wanna add from time to time new timestamp, timestamps are added under different columns headers in different time and every column should be able to have different amount of timestamps (rows). this will be like list of entities(column headers) with list of timestamps(rows) under them

my problem: i couldn't find out how to add timestamp under just one specific column header. when i tried to use INSERT i had to insert something under all columns not just under one i wanted, with UPDATE i do not know how to do it at all because timestamps are added over time and before that their "boxes"(by box i mean one specific space in certain row under certain column, sorry if there is name for it) are empty/are not there

if someone have any thought about how it could be done/about alternative approach/what i get wrong.. i would love to hear it :)

i tried "INSERT" but i didn't find any way to insert only under specific column header, just whole row/under all columns (i.e. INSERT INTO x VALUES (v1, v2, v3...)

thanks for any comment :)

...if i didn't explained something enough please JUST ASK ABOUT IT so i can be more detailed where it is needed or you can always just go to another question and someone else may answer this..

Upvotes: 0

Views: 493

Answers (2)

Amin Rezaie
Amin Rezaie

Reputation: 31

You can do like this:

INSERT INTO table_name (time_stamp_col) values ('your_val')

Upvotes: 0

GMB
GMB

Reputation: 222722

It is perfectly fine to not insert into all columns (as long as the columns you want to ignore are nullable, or have a default value).

For this, you need to enumerate the columns that you want to insert into:

insert into x (col1, col2, col3) values ('val1', 'val2', 'val3')
             --^----> list of target column list 

Note that it is considered best practice to always enumerate the columns for insert (one of the reason being that it prevents the query from failing when the table structure is modified, as you are experiencing here).

Upvotes: 3

Related Questions