I
I
Ivan Filatov2015-06-17 10:24:22
.NET
Ivan Filatov, 2015-06-17 10:24:22

How to save Excel/DataTable table to DB (MS SQL Server)?

There are DataTable (Excel) tables with a different number of columns, rows, as well as any options for column types.
How best to save a table to a database (MS SQL Server)?
to save:
- column names and their types
- all rows, cells of these tables, data in general.
There is no clear table format. It is always a set of columns from 1 to N. With data from 1 to M rows.
You don't want to create a table in the database with 100 allownull columns of the form (col1, col2, .... col100) and fill in its initial columns, and skip others if the table is smaller. Somehow not pretty.
Saving each cell individually is not optimal, it takes a huge amount of time to save and read.
I'm thinking of converting the table to a simple CSV format and saving it as text, then turning it back into a DataTable.
Maybe there are other options?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Stanislav Makarov, 2015-06-17
@NYMEZIDE

> There is no clear format for tables.
So the relational model as such is not suitable for you. There are two options here:
1) Entity-Attribute-Value (maybe this is what you meant by "Save each cell separately", well then it's up to you. Of course, it will work slower than a normal table, but you don't have a schema, there's nothing to be done)
2) JSON/XML. Here, either fields of type XML, or hello document-oriented DBMS.
The second option is suitable if selections inside the table are not needed or are rarely needed (since you are talking about CSV). If you need it often, then EAV is the one.

A
Arman Toksimbaev, 2015-06-17
@toxicdream

Can store/import different tables (with different structures) into different tables => MyCoolTable001, MyCoolTable002 ...
And in extreme cases, create a metatable in which to store that MyCoolTable001 was imported from D:\Important data\111.xlsx in 2015-05 -06 04:34:57.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question