0

Im currently building an app to help with day to day development of our app development team.

Im wondering is there any sort of easy way to generate code to generate SQL tables that have already been created for MSSQL ?

I ask this because in MSSQL you can right click a table and choose the generate scripts option and it will create the code neccessary to build that particular table ?

Is there any way via SQL to leverage that function, or anyway within ColdFusion to create this code, without having to write it from scratch ?

Matt Busche
  • 13,789
  • 5
  • 34
  • 58
user125264
  • 1,711
  • 1
  • 23
  • 47
  • 2
    "in MSSQL you can right click a table and choose the generate scripts option and it will create the code neccessary to build that particular table", yes, use that. Why do you want CF to do it? – Henry Jan 28 '14 at 23:17
  • 4
    It's not really MSSQL thats doing that fo you...it's Microsoft SQL Server Management Studio, the tool that sits on top of it. There should be other 3rd party tools that will do the same for you. That said, it is possible to script it out of the tables that store the schema information (in the same manner SSMS or any other 3rd party tool). – Twelfth Jan 28 '14 at 23:23

2 Answers2

0

I would use something like this SQL server query to get the list of columns in a table along with Data types, NOT NULL, and PRIMARY KEY constraints to get the table names and columns and data types and construct something with the results to write a script for creating the tables.

Community
  • 1
  • 1
  • thank you so very much for this. this is definitely the most elegant approach to generating SQL Installation scripts. – user125264 Jan 31 '14 at 06:52
  • You could then use the 'exportSQLTable" UDF to generate the SQL script to import the data. http://cflib.org/udf/exportSQLTable – James Moberg Oct 28 '16 at 21:46
0

You can right click and generate the script from SQL. Then in CF, you can have something like this:-

<cfquery name = "query1" dataSource = "ds1">
   type in the generated script from SQL here
</cfquery>`
Leigh
  • 28,424
  • 10
  • 49
  • 96
Anit Kumar
  • 1,218
  • 8
  • 14
  • You need to additionally the "GO" command from the SQL used with CFQuery: REReplaceNoCase( TheSQL, "\nGO", ";", "ALL") – James Moberg Oct 28 '16 at 21:22