Step by step process for creating SQL Script for Demo Table in SQL Server

Suppose that the "Employee Table" as shown in the attached snapshot, is actually present inside my SQL Server Database.Now I have to ask some question regarding this table, therefor I want to post a SAMPLE of this table on some Database Help Forum.

My question is - how do I prepare the SQL Script for doing this work in the most simple manner ? Just as the code shown in the snapshot has various parts - Create Database, Create Table, Insert Into. If we run this code in SQL Server then we will get the exact table as an output.

Please give me the simplest method to prepare such SQL Script for any table present in my SQL Server Database.I hope I do not have to Manually Write the "Create Table and Insert Into" parts for creating such SQL Scripts.

Thanks a lot for your help.

PS: I have taken that snapshot from this article -

Please do not be confused by any other material given in that article. Our interest is ONLY in the very first snap given on the very top which shows the script for creating the Employee Table.How to prepare such SQL Script for creating a Sample Table
happy 1001Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Koen Van WielinkBusiness Intelligence SpecialistCommented:
Probably the simplest way is to right click on the table and select "Script table as", then "Create to". This will result in a create script for the table. Next, run a select statement which retrieves the sample data you wish to share. Select all the data, right click and select "copy with headers". Open an excel file and paste the result, then save as Excel or CSV.
If you post the script and the sample data file on this forum, we can recreate the table and import the sample data from the Excel file.
Deepak ChauhanSQL Server DBACommented:
You can use Generate script wizard in sql server. You can script out all objects or specific one according to your requirement.

1. Right click on database > Task> generate script.

Next all steps are self explainatory.  Please set the advance option "schema and data" if you want to generate script with data.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
happy 1001Author Commented:
Thank you so much Deepak Ji

That is exactly what I was looking for.  This solution works perfectly for my needs. Your answer was short and to the point. The snapshot and the highlighted portion proved out to be very helpful.

Thanks again
happy 1001Author Commented:
Thank you for your help Koen Van Wielink. I was using a similar method as you described, but that involved multiple steps and I had to do copy paste work every time.
The solution provided by Deepak solves that trouble.

Thanks for your reply.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.