# Database Insert activity

**URL:** <https://forum.uipath.com/t/database-insert-activity/90457>\
**Category:** Help\
**Tags:** database, activities\
**Created:** [January 24, 2019, 3:57pm UTC](https://forum.uipath.com/t/database-insert-activity/90457 "2019-01-24T15:57:05Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![lavint](https://avatars.discourse-cdn.com/v4/letter/l/8c91f0/32.png) [@lavint](https://forum.uipath.com/u/lavint)\
**Post date:** [January 24, 2019, 3:57pm UTC](https://forum.uipath.com/t/database-insert-activity/90457/1 "2019-01-24T15:57:05Z")

</div>

Hi,

I am trying to use the INSERT database activity but it gave me an error

 ![image](https://global.discourse-cdn.com/uipath/original/3X/4/9/49e1a4f6d2df2b7bd30811af1dbebb3af3ae3068.png)

![image](https://global.discourse-cdn.com/uipath/original/3X/e/d/edc28451298248142659ded607a1c36c6e029b30.png)

My datatable doesn’t have an ID field though…

I am able to SELECT from the database table, but able to insert.. Can you please help?  
I want to do a bulk insert instead of reading “For-Each-Row” from the datatable

 ![image](https://global.discourse-cdn.com/uipath/original/3X/c/3/c362d2a50ee44762d5d934d4be9058d1bf6208c1.png)

Any suggestion?? Thanks!

---

<div class="post-metadata">

**Author:** ![TimK](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/timk/32/264334_2.png) [@TimK](https://forum.uipath.com/u/TimK)\
**Post date:** [January 24, 2019, 4:10pm UTC](https://forum.uipath.com/t/database-insert-activity/90457/2 "2019-01-24T16:10:05Z")

</div>

Are the tables like for like in terms of column names i.e. your datatable (outputDT) and your SQL datatable?

---

<div class="post-metadata">

**Author:** ![lavint](https://avatars.discourse-cdn.com/v4/letter/l/8c91f0/32.png) [@lavint](https://forum.uipath.com/u/lavint)\
**Post date:** [January 24, 2019, 4:15pm UTC](https://forum.uipath.com/t/database-insert-activity/90457/3 "2019-01-24T16:15:28Z")

</div>

Yes. The columns are the same. Basically I have these data loaded into the database to create table. And then I am loading the same data to the UiPath datatable and then try to append to the database table that I created.

---

<div class="post-metadata">

**Author:** ![TimK](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/timk/32/264334_2.png) [@TimK](https://forum.uipath.com/u/TimK)\
**Post date:** [January 24, 2019, 4:36pm UTC](https://forum.uipath.com/t/database-insert-activity/90457/4 "2019-01-24T16:36:39Z")

</div>

Seems strange it thinks there is an ‘ID’ column somewhere.

Have you tried outputting each data table to confirm - is there a auto increment column (‘ID’) within your SQL data table?

---

<div class="post-metadata">

**Author:** ![lavint](https://avatars.discourse-cdn.com/v4/letter/l/8c91f0/32.png) [@lavint](https://forum.uipath.com/u/lavint)\
**Post date:** [January 24, 2019, 4:43pm UTC](https://forum.uipath.com/t/database-insert-activity/90457/5 "2019-01-24T16:43:45Z")

</div>

Yes. I output the datatable to a CSV file and I don’t see any column called ID

---

<div class="post-metadata">

**Author:** ![lavint](https://avatars.discourse-cdn.com/v4/letter/l/8c91f0/32.png) [@lavint](https://forum.uipath.com/u/lavint)\
**Post date:** [January 24, 2019, 5:03pm UTC](https://forum.uipath.com/t/database-insert-activity/90457/6 "2019-01-24T17:03:10Z")

</div>

Anyone has any idea where this ‘ID’ comes from? I really don’t have a column ID…

now I am basically taking the data from the table and insert the same data into the same table. Still get the same error

 ![image](https://global.discourse-cdn.com/uipath/original/3X/9/5/95b9d635660b34e9f1ef75d393a1240725033661.png)

Then I read excel directly again and change the column names to lower case and got this error  
 ![image](https://global.discourse-cdn.com/uipath/original/3X/7/2/729d76aac5719654b032a05ed6c9ad88390ed2a0.png)

I think the column names maybe an issue… but again… I don’t have a column name id…

---

<div class="post-metadata">

**Author:** ![palindrome](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/palindrome/32/42301_2.png) [@palindrome](https://forum.uipath.com/u/palindrome)\
**Post date:** [January 24, 2019, 5:22pm UTC](https://forum.uipath.com/t/database-insert-activity/90457/7 "2019-01-24T17:22:21Z")

</div>

Can you show the design of table in sql ?

---

<div class="post-metadata">

**Author:** ![lavint](https://avatars.discourse-cdn.com/v4/letter/l/8c91f0/32.png) [@lavint](https://forum.uipath.com/u/lavint)\
**Post date:** [January 24, 2019, 5:26pm UTC](https://forum.uipath.com/t/database-insert-activity/90457/8 "2019-01-24T17:26:16Z")

</div>

like this?

![image](https://global.discourse-cdn.com/uipath/original/3X/2/b/2b993fa0abfd74a8d155e9b94315d384e83b9f19.png)  
 ![image](https://global.discourse-cdn.com/uipath/original/3X/1/6/16e27500275b4612f66ab7f37ed03d68cbd5af21.png)

there is an IDENT ITEM ID … not sure if it’s because the column name have spaces…  
I will check it out again with a fewer column database table I guess…

---

<div class="post-metadata">

**Author:** ![palindrome](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/palindrome/32/42301_2.png) [@palindrome](https://forum.uipath.com/u/palindrome)\
**Post date:** [January 24, 2019, 5:28pm UTC](https://forum.uipath.com/t/database-insert-activity/90457/9 "2019-01-24T17:28:20Z")

</div>

yeah, can you change space to underscore and also for testing keep all datatypes as nvarchar(255).  
so drop this table and create a new one.

---

<div class="post-metadata">

**Author:** ![lavint](https://avatars.discourse-cdn.com/v4/letter/l/8c91f0/32.png) [@lavint](https://forum.uipath.com/u/lavint)\
**Post date:** [January 24, 2019, 5:38pm UTC](https://forum.uipath.com/t/database-insert-activity/90457/10 "2019-01-24T17:38:37Z")

</div>

Thank you! yes… it’s because of column names have the space… now I get another error of another column name…  
 ![image](https://global.discourse-cdn.com/uipath/original/3X/4/3/4384a4374832cd83db6277d699dc1a9ee642d5c9.png)

However, now my question is that in the actual database which contains millions of live data, the column names have space in them…

If I change my excel files to have no spaces in the column names, the column names will be different from the actual database and those columns won’t be matched…?

Basically the actual database and the excel file input have exactly the same name now… what can I do at this point for a bulk upload? just like import as easy as in an import wizard…

---

<div class="post-metadata">

**Author:** ![palindrome](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/palindrome/32/42301_2.png) [@palindrome](https://forum.uipath.com/u/palindrome)\
**Post date:** [January 24, 2019, 6:40pm UTC](https://forum.uipath.com/t/database-insert-activity/90457/11 "2019-01-24T18:40:42Z")

</div>

you can rename column of datatable in uipath. so I dont think it should be a problem.

`dataTable.Columns["ColumnName"].ColumnName = "newColumnName";`

---

<div class="post-metadata">

**Author:** ![lavint](https://avatars.discourse-cdn.com/v4/letter/l/8c91f0/32.png) [@lavint](https://forum.uipath.com/u/lavint)\
**Post date:** [January 24, 2019, 7:19pm UTC](https://forum.uipath.com/t/database-insert-activity/90457/12 "2019-01-24T19:19:25Z")

</div>

Hello @palindrome  
It doesn’t where I rename the new data’s column names - in Uipath data table or in the excel sheet. What I meant is that after I change the new data’s column names with \_ or no space, it won’t match the existing database’s column names. And I have just proved it

.Net SqlClient Data Provider : Invalid column name ‘period\_number’.  
Invalid column name ‘week\_number’. — in database it’s “week number”  
Invalid column name ‘route’. — in database it’s “route #”  
Invalid column name ‘ident\_item\_id’. — in database it’s “ident item id”

You know what I mean?  
What is the best approach for this scenario? I don’t prefer to change the column name of the original database unless it’s absolutely necessary. Thanks!

---

<div class="post-metadata">

**Author:** ![palindrome](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/palindrome/32/42301_2.png) [@palindrome](https://forum.uipath.com/u/palindrome)\
**Post date:** [January 25, 2019, 2:26am UTC](https://forum.uipath.com/t/database-insert-activity/90457/13 "2019-01-25T02:26:48Z")

</div>

If you can not rename columns in database then only way to solve it is by calling a store procedure in database.

Check this out: [sql - Create a stored procedure to insert new data into a table - Stack Overflow](https://stackoverflow.com/questions/20544752/create-a-stored-procedure-to-insert-a-new-data-in-a-table)

---

<div class="post-metadata">

**Author:** ![zouchen007](https://avatars.discourse-cdn.com/v4/letter/z/5f8ce5/32.png) [@zouchen007](https://forum.uipath.com/u/zouchen007)\
**Post date:** [April 20, 2020, 9:15am UTC](https://forum.uipath.com/t/database-insert-activity/90457/14 "2020-04-20T09:15:06Z")

</div>

Hi plindrome, where should i put the rename column script btw.

thanks!  
Chen

---

<div class="post-metadata">

**Author:** ![Snehal14Kapse](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/snehal14kapse/32/182678_2.png) [@Snehal14Kapse](https://forum.uipath.com/u/Snehal14Kapse)\
**Post date:** [February 4, 2021, 9:56pm UTC](https://forum.uipath.com/t/database-insert-activity/90457/15 "2021-02-04T21:56:31Z")

</div>

Hello @lavint Use Read Workbook Activity instead of using Excel Read Range Activity. Extra columns/rows will be added if you don’t provide exact range in Excel Read Activity.

Store Result in Data-table & use Insert Activity to store data inside Database.
