I have a table schema in an exported .sql file (text). Is there any way to use that to create an identical table (with the name changed of course)?
The file was created using script table as -> create to -> file.
TIA
March 11, 2021 at 9:17 pm
If you want the data as well as the table, that method won't work. If you ONLY want the table schema and don't care about the data, that will work fine; you just need to open the .sql file and find and replace the old name with the new one.
The above is all just my opinion on what you should do.
As with all advice you find on a random internet forum - you shouldn't blindly follow it. Always test on a test server to see if there is negative side effects before making changes to live!
I recommend you NEVER run "random code" you found online on any system you care about UNLESS you understand and can verify the code OR you don't care if the code trashes your system.
March 12, 2021 at 1:43 pm
Yeah, I want just the schema. But how do I import the sql file into the database to create a new table?
That part is easy then - Run the script.
The script is just plain TSQL used for re-creating the object. It can be opened in SSMS or SQLCMD and run against the database. You can even open it in notepad to review the code behind it.
The above is all just my opinion on what you should do.
As with all advice you find on a random internet forum - you shouldn't blindly follow it. Always test on a test server to see if there is negative side effects before making changes to live!
I recommend you NEVER run "random code" you found online on any system you care about UNLESS you understand and can verify the code OR you don't care if the code trashes your system.
March 13, 2021 at 2:37 am
Yeah, I want just the schema. But how do I import the sql file into the database to create a new table?
Bulk Insert the text file as a single blob into a variable and then execute the variable.
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply