0

For example I have file names A, B, C, D then I want to insert them in database in a single field then it will look like this in a table

ID | filename  | PATH | DATE         |
1  | A, B, C, D| DOCX | Mar. 10, 2017|
mykelens
  • 29
  • 2
  • 1
    this is not the way you should be using a RDBMS. There are thousands of questions here from people who took this path and are now stuggling Don't save CSV in a column http://stackoverflow.com/questions/41304945/best-type-of-indexing-when-there-is-like-clause/41305027#41305027 http://stackoverflow.com/questions/41215624/sql-table-with-list-entry-vs-sql-table-with-a-row-for-each-entry/41215681#41215681 – e4c5 Mar 10 '17 at 05:08
  • 1
    **Never do that.** See normalization. – Gurwinder Singh Mar 10 '17 at 05:08
  • you can also have a look at `serialize` in mysql helps you to keep data in one column – Nishant Nair Mar 10 '17 at 05:10
  • One option is that use serialize in it and another options make other table for it. Never save data in one column because it rise problem in future. – Bhavin Mar 10 '17 at 05:11
  • you have an array of ABCD value? – ImBhavin95 Mar 10 '17 at 05:16
  • What if we have n number of same data, like here filename might have A,B,C,D,E.....n?? – Rohan Khude Mar 10 '17 at 05:18

2 Answers2

1

Never put comma separated data like A, B, C, D in a single column. Instead use Normalization.

Normalization is a database design technique which organizes tables in a manner that reduces redundancy and dependency of data. It divides larger tables to smaller tables and link them using relationships.

In your case make an another table like tbl_filenames and put multiple entries of file name in it and bind it with your base table with \

id -> file_id basic

means on each entry in base table their are multiple file entry in tbl_filenames and bond together user id->file_id

Mayank Pandeyz
  • 25,704
  • 4
  • 40
  • 59
0

Just concatenate those & insert like a single value. Its up to you if you wanna do that, But its against normalization & will make system harder to handle, but after all if you insist on doing that:

INSERT INTO tblName (`ID`, `filename`, `PATH`, `DATE`) VALUES (1, "A" . ", " . "B" . ", " . "C" . ", " . "D", "DOCX", "Mar. 10, 2017")