Rom
Rom

Reputation: 63

INSERT INTO statement in a specific column

For example i have table with a different field names(column), lets say 5 columns and all of them are empty. And i wanted to insert data in one specific column. Is it possible? I'm looking for example of this, but unlucky to find one. Most of insert into statements examples required all columns to be filled. If possible, can you give me the correct syntax? I'm sorry if i'm lacking research or it's already been asked, it's ok if you will redirect me to the link.

Upvotes: 3

Views: 8614

Answers (2)

sstan
sstan

Reputation: 36473

The documentation on how to construct an INSERT INTO statement is here: INSERT INTO Statement (Microsoft Access SQL).

But basically, you just need to be explicit about which columns you want to insert values for, and omit the other ones, like this:

INSERT INTO table (colname) VALUES ('colvalue')

What happens to the fields you omit? The documentation says:

When you do not specify each field, the default value or Null is inserted for missing columns.

Upvotes: 1

candlejack
candlejack

Reputation: 1209

If you want insert on column3, leaving empty the other:

INSERT INTO table_name (column1,column2,column3,column4,column5)
VALUES ("","","VALUE","","");

The other part of program would UPDATE the other columns:

UPDATE table_name
SET column1=value1,column2=value2,column4=value4,column5=value5
WHERE some_column=some_value;

Upvotes: 1

Related Questions