# Creating a Table in code

**URL:** <https://www.dynamicsuser.net/t/creating-a-table-in-code/9592>\
**Category:** Developers Forum\
**Created:** [January 19, 2005, 10:27am UTC](https://www.dynamicsuser.net/t/creating-a-table-in-code/9592 "2005-01-19T10:27:55Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![asnape](https://avatars.discourse-cdn.com/v4/letter/a/f14d63/32.png) [@asnape](https://www.dynamicsuser.net/u/asnape)\
**Post date:** [January 19, 2005, 10:27am UTC](https://www.dynamicsuser.net/t/creating-a-table-in-code/9592/1 "2005-01-19T10:27:55Z")

</div>

Hey, I’m doing a data migration from an SQL database into a Native Navision 370 database. I want to create all the SQL tables and fields in Navision. Im using the sysobjects table in the SQL database to get the table names of all tables in the db, but am struggling to create them in navision. Here is an extract of code: ` IF NOT RS.EOF THEN REPEAT _ObjectRec.INIT; _ObjectRec.Type := _ObjectRec.Type::Table; _ObjectRec.ID := "_TableNo."; // _ObjectRec.Name := COPYSTR(GetTextField2('name', RS),1, MAXSTRLEN(_FieldsRec.TableName)); _ObjectRec."Version List" := 'System Created for Migration'; _ObjectRec.INSERT(TRUE); "_TableNo." := "_TableNo." + 1; RS.MoveNext; UNTIL RS.EOF; ` The table will create but the blob is empty and I can not design the table or compile it (says the table is empty). I’ve tried using the Field table to create a primary key inside the table, but again it errors. I’m sure I did this a few years ago and can’t think what is wrong. Can you help? Regards, Alex

---

<div class="post-metadata">

**Author:** ![stryk](https://avatars.discourse-cdn.com/v4/letter/s/ee59a6/32.png) [@stryk](https://www.dynamicsuser.net/u/stryk)\
**Post date:** [January 19, 2005, 1:06pm UTC](https://www.dynamicsuser.net/t/creating-a-table-in-code/9592/2 "2005-01-19T13:06:15Z")

</div>

Hi! Maybe you could create a simple template table - the old-fashioned way using the Object Designer - with just one field. Now, create a little program to export the “BLOB Reference” of that table (from Object Table) using the the BLOB.EXPORT method. Finally, add some code to your function to import this template BLOB reference by BLOB.IMPORT method … Have not tried, maybe that works … Regards,

---

<div class="post-metadata">

**Author:** ![stryk](https://avatars.discourse-cdn.com/v4/letter/s/ee59a6/32.png) [@stryk](https://www.dynamicsuser.net/u/stryk)\
**Post date:** [January 19, 2005, 1:12pm UTC](https://www.dynamicsuser.net/t/creating-a-table-in-code/9592/3 "2005-01-19T13:12:29Z")

</div>

Another option could be to create an Object-Text-File containing all table- and field-information; than import this file via “Object Designer” and compile the new objects …

---

<div class="post-metadata">

**Author:** ![asnape](https://avatars.discourse-cdn.com/v4/letter/a/f14d63/32.png) [@asnape](https://www.dynamicsuser.net/u/asnape)\
**Post date:** [January 19, 2005, 2:23pm UTC](https://www.dynamicsuser.net/t/creating-a-table-in-code/9592/4 "2005-01-19T14:23:45Z")

</div>

Thanks guys, I decided to stop wasting time with this and just built a text file with the 250 tables and an integer key. The fields can dynamically be created using the Record Set so it will still save alot of time (as long as we can map the SQL types correctly!). If you do have the solution for the original problem I’d still like to know. Alex.
