Creating a viewscript

From Species File Help
(Difference between revisions)
Jump to: navigation, search
(made page)
 
(Change "drop & create" to "alter" per discussion with JRF)
 
Line 1: Line 1:
 
== Creating a viewscript ==
 
== Creating a viewscript ==
  
 +
This is a new simpler way to create a viewscript that will not break when using the Apex Taxon tools and will provide better feedback if an error occurs. (7/16/13 EEF & JRF)
  
 
In order to create or update a view:
 
In order to create or update a view:
* Design (or edit) the view in SSMS. Once you are satisfied with the view; create a viewscript by using the "DROP and CREATE" to clipboard command. (Right click on saved view in the object explorer, => Script View as => DROP And CREATE To => Clipboard)
+
* Design (or edit) the view in SSMS. Once you are satisfied with the view; create a viewscript by using the "ALTER" to clipboard command. (Right click on saved view in the object explorer, => Script View as => ALTER To => Clipboard)
  
 
* Create (or edit) your viewscript file in Visual Studio. All the view scripts are kept in the SQL project in the "ViewScripts" directory. Your view name (and filename) should start with "view". The file type is SQL. There is no view template, but the file should have some of the same header as any other SQL file (see Common/Support/ProgrammingRelated/FileTemplates/spTemplate.sql). Included fields should be:
 
* Create (or edit) your viewscript file in Visual Studio. All the view scripts are kept in the SQL project in the "ViewScripts" directory. Your view name (and filename) should start with "view". The file type is SQL. There is no view template, but the file should have some of the same header as any other SQL file (see Common/Support/ProgrammingRelated/FileTemplates/spTemplate.sql). Included fields should be:
Line 25: Line 26:
 
|GO
 
|GO
 
|}
 
|}
</code>) There will be one before and after the code that drops the view if it exists.
+
</code>)  
 
</li>
 
</li>
  
 
<li>
 
<li>
The code that sets ANSI_NULLS and QUOTED_IDENTIFIER should remain.
+
Delete the code that sets ANSI_NULLS and QUOTED_IDENTIFIER. This is set in the Apex Taxon utilities that will update the scripts in the database. (e.g. <code lang="text">
 +
{|class="wikitable1"
 +
|-
 +
|
 +
|SET ANSI_NULLS ON
 +
|-
 +
|
 +
|GO
 +
|-
 +
|
 +
|SET QUOTED_IDENTIFIER ON
 +
|-
 +
|
 +
|GO
 +
|}
 +
</code>)
 
</li>
 
</li>
  
<li> The actual "CREATE VIEW" code must be modified. The tool to update database objects run from ApexTaxon does not handle a "CREATE VIEW" command properly. It must be modified into an "EXEC" command. Prepend "CREATE VIEW" with <br /><br />
+
<li>  
<code lang="text">EXEC dbo.sp_executesql @statement = N'</code>
+
Delete the final "GO" at the bottom of the script.
<br /><br />
+
and add a trailing " <span style="color:tomato">'</span> " to the end of the command (just above the next "GO").
+
 
</li>
 
</li>
 
</ul>
 
</ul>
 
* The final part of the pasted script controls the display of the view diagram in the SSMS editor. It can be left or deleted as you prefer.
 
  
 
Your viewscript it now complete and can be returned to source control. You can run the script to update the view in the db or it will be updated the next time full builds are done and database objects are updated.
 
Your viewscript it now complete and can be returned to source control. You can run the script to update the view in the db or it will be updated the next time full builds are done and database objects are updated.
 +
  
 
[[Category:Developers]]
 
[[Category:Developers]]

Latest revision as of 15:35, 16 July 2013

[edit] Creating a viewscript

This is a new simpler way to create a viewscript that will not break when using the Apex Taxon tools and will provide better feedback if an error occurs. (7/16/13 EEF & JRF)

In order to create or update a view:

  • Design (or edit) the view in SSMS. Once you are satisfied with the view; create a viewscript by using the "ALTER" to clipboard command. (Right click on saved view in the object explorer, => Script View as => ALTER To => Clipboard)
  • Create (or edit) your viewscript file in Visual Studio. All the view scripts are kept in the SQL project in the "ViewScripts" directory. Your view name (and filename) should start with "view". The file type is SQL. There is no view template, but the file should have some of the same header as any other SQL file (see Common/Support/ProgrammingRelated/FileTemplates/spTemplate.sql). Included fields should be:
    • Copyright
    • File
    • Name
    • Desc (description)
    • Auth (author)
    • Date
    • Change History
  • Paste the clipboard code from SSMS into the section after the header comments.
  • Delete the segments that set the database. (e.g.
    USE [Lygaeoidea1]
    GO

    )

  • Delete the code that sets ANSI_NULLS and QUOTED_IDENTIFIER. This is set in the Apex Taxon utilities that will update the scripts in the database. (e.g.
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO

    )

  • Delete the final "GO" at the bottom of the script.

Your viewscript it now complete and can be returned to source control. You can run the script to update the view in the db or it will be updated the next time full builds are done and database objects are updated.

Personal tools
Namespaces

Variants
Actions
Navigation
Species Files
Wiki
Toolbox