0

I created several tables using the gui from SQL Server. Now I want to see the actual "code". But I don't know where to find it.

For example, as I was right clicking "databases" and then choosing the "create table" option and filling in column names and the datatypes from the drop down menu, I assume there must be a " CREATE TABLE Happy_Life (id INTEGER PRIMARY KEY, name TEXT, age INTEGER) " somewhere.

My question is where?

7
  • 3
    Right-click on the table, and choose CREATE to->New query editor window from the Script as submenu. Commented Jul 15, 2019 at 1:43
  • There're serveral ways. Try ` cat ~/.mysql_history` to see command history or you can find .sql file in backup folder Commented Jul 15, 2019 at 1:44
  • @KienPham The OP isn't using MySQL. Commented Jul 15, 2019 at 1:45
  • @KenWhite You are god's gift to mankind. First suggestion worked.... Commented Jul 15, 2019 at 1:45
  • 2
    @KienPham: cat ~/.mysql_history won't do a thing if a) you're using SQL Server instead of MySQL, and b) not running on a *nix OS. Commented Jul 15, 2019 at 1:46

2 Answers 2

5

Right-Click on your table

  1. Script Table As
  2. Create To
  3. New Query Editor Window enter image description here
Sign up to request clarification or add additional context in comments.

1 Comment

Similar to this, you can generate scripts for all tables (and other objects like views, stored procedures, indexes, etc.) by right clicking on the database, and selecting Tasks -> Generate Scripts.
1

To generate script of entire database & all database objects (Schema only or Schema with data) or script for only specific database objects like tables,views,stored procedures etc. The steps are as follows.

Right click on Database object -> Task -> Generate Script enter image description here

Click on Next enter image description here

Select The database object to script -> Next enter image description here

Advanced -> Type of data to be script -> OK enter image description here

Set file name with location -> Next enter image description here

enter image description here

Finally click on Finish.

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.