3

I need to dump the database structure for a SQL Server database, but I need to do it from a SQL query or sqlcmd script.

Is there a valid way to do it?

Thanks

3
  • 1
    You want to write a query that will script your entire database? Good luck with that. There are SO MANY things you need to script. It would take far less time and effort to create a backup and restore it. Commented May 1, 2018 at 21:20
  • 1
    Or do it from the GUI in SSMS. Notice how that is also fairly complex as far as options are concerned. If you really wanted to build something to mimic that you could use profiler to see what is being called but it won't be easy to replicate. Commented May 1, 2018 at 21:21
  • 1
    Possible duplicate of stackoverflow.com/q/5771047/1260204. See also google.com/… Commented May 1, 2018 at 21:28

2 Answers 2

5

Open object explorer, right click db, tasks, generate scripts, next, script entire databse and all database objects, save to file, next, next, finish.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks, but sorry I’ve forgot to say that I need to do this from SQL query!
@FedericoAguirre When you finish, it scripts all the TSQL out to a file. Did you do the steps above?
4

Follow the complete steps to generate script with data.

1 enter image description here

2 enter image description here

3

enter image description here

4

enter image description here

5

enter image description here

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.