Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 recreating exisitng tables in a new DB

Author  Topic 

zubair
Yak Posting Veteran

67 Posts

Posted - 2009-02-05 : 11:13:35
I need to perform the following task:

1.get a sql script of a table including primary key, foreign keys and contraints

2. running the sql script above in another database

I need to do this on a regular basis. Is there a way to automate this task instead of manually having to get the script via enterprise manager and then copying and pasting into query anayluser and running against new database? I think this can be done via OSQL? Does anyone have an example i could base mine on? Thx

sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2009-02-05 : 11:20:21
You can use Generate Script Task in SSMS.
Go to Top of Page

zubair
Yak Posting Veteran

67 Posts

Posted - 2009-02-05 : 11:49:14
Can you tell me how to do this? I am a bit new qith sql server. Do you have an example?
Go to Top of Page

sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2009-02-05 : 11:54:15
Right Click Database-Task
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-02-05 : 12:05:16
http://msdn.microsoft.com/en-us/library/ms178078.aspx
Go to Top of Page

zubair
Yak Posting Veteran

67 Posts

Posted - 2009-02-05 : 12:12:00
sodeep, i don't think you're gettin what i'm trying to do. I DON't want to use enterprise manager... thats the whole point of automation.... not very helpful at all.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-02-05 : 12:17:37
you can use SMO objects for that

http://msdn.microsoft.com/en-us/library/ms162153.aspx
Go to Top of Page

sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2009-02-05 : 12:20:54
quote:
Originally posted by zubair

sodeep, i don't think you're gettin what i'm trying to do. I DON't want to use enterprise manager... thats the whole point of automation.... not very helpful at all.



Put the generated script in SQL job and automate(schedule)it whenever you need to.
Go to Top of Page
   

- Advertisement -