Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Script to give me create constraint syntax

Status
Not open for further replies.

MikeJones

Programmer
Nov 1, 2000
259
GB
Does anyone have a script they wouldn't mind posting that given a table would produce the text necessary to create all the constraints on that table?

Cheers,

Mike.
 
Why not just export the table (with or without the data) and include the constraints?
 
I need to "refresh" or more accurately fix alot of constraints on a number of tables. All of these tables have some constraints but they are all incorrect and they contain data, and some of them might even be on customer sites *ahem*

So I'm not in a position to do anything export / import wise. least of all becasue all these tables already have lots of data in them.

So I figured the best I could do was clear a night when no other updates were planned and rebuild the constraints by dropping and re-creating them.

Now the problem is I don't have a script with the constraints. I do however have a master account with them set how they should be...
 
You should be able to create a query that queries sys.all_constraints and sys.all_cons_columns and creates the sql to reproduce them but you probably already knew that. SOL
The best thing about banging your head against a wall is when you stop.
 
Your best bet may be to get hold of a copy of TOAD ( if you don't already have it ) and use the export table scripts function in this. This will create the scripts to create the tables and constraints, you could then write a text parsing program to strip the create table syntax out. This is how I would do it anyway. SOL
The best thing about banging your head against a wall is when you stop.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top