How to copy a table (with data and without data) within the same application/db/instance?

jgomes
Kilo Contributor
Hi!
 
  1. How do we copy a table? (identical everything (except name/sys_id, of course) in the same db/instance)
  2. How do we  clone a new empty table with the  same schema/definitions/etc. as an existing table but no records?
 
Cheers,
 
--
Jorge
1 ACCEPTED SOLUTION

robpickering
ServiceNow Employee
ServiceNow Employee

Jorge,



I'm going to answer in reverse order...



If you wish to create a copy of the table structure, but without any records, the cleanest way of performing this is to extend the table.   You'll have to mark the parent table as 'extensible', but the result will be an identical table as the parent, without any records.   You would then also have the option to add custom fields to the child table which would not appear in the parent; while also being able to add new fields to the parent, which would automatically show up in the child.



Once you extend the table, you can export the rows on the parent table and then re-import them into the child table to make a copy.



There's a lengthy discussion on this same topic found here:   Is there any way to copy an entire table with a new name but same fields?



-Rob


View solution in original post

5 REPLIES 5

robpickering
ServiceNow Employee
ServiceNow Employee

Jorge,



I'm going to answer in reverse order...



If you wish to create a copy of the table structure, but without any records, the cleanest way of performing this is to extend the table.   You'll have to mark the parent table as 'extensible', but the result will be an identical table as the parent, without any records.   You would then also have the option to add custom fields to the child table which would not appear in the parent; while also being able to add new fields to the parent, which would automatically show up in the child.



Once you extend the table, you can export the rows on the parent table and then re-import them into the child table to make a copy.



There's a lengthy discussion on this same topic found here:   Is there any way to copy an entire table with a new name but same fields?



-Rob


Thank you for that reply, Rob!


(Sorry for my own late response)



After discussing with my Tech Lead, my question is slightly more complex.



How to copy a table (with data and without data):


  1. within the same application/db/instance?
  2. AND have the new table be a sibling in the table hierarchy (not a child) so that all records in the new table will be in the same parent table hierarchy as the old table

(Disclaimer: I cannot claim fully understand the parent/extend behavior in ServiceNow, so my questions are really newbie-level - Sorry)


Hello, is there any possible impact to the database structure or data if an no-extensible table is marked as extensible to do this? for example HR Profile [sn_hr_core_profile] table

 

Thanks

how to I copy tableA to be tableB without tableB extending any table?  I do not want tableB, after being copied from tableA, to extend any table.