0

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..

1
  • 1
    Please avoid using vulgar language. Commented Apr 2, 2020 at 13:11

2 Answers 2

3

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).

Sign up to request clarification or add additional context in comments.

3 Comments

thank you :) one more question :D if names of columns are numbers, how can i do it? because there is error when i do it as you said but if i put letter before number its ok :/ ..i tried " and ' but didnt help
@bfha9p3wbnfa: you can enclose the column name within double quotes: insert into x ("1", "2", "3") values(...). Note that using identifiers that require quoting makes things more complicated for no value added...
@bfha9p3wbnfa If you will SHOW CREATE TABLE tbl_name; you may find you have usable column names rather than using the "1" technique.
0

You can do like this:

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.