TSQL snippets for snippetsEmu


/ Published in: Other
Save to your folder(s)

These snippets can be used with TSQL files (assuming .sql extension) by saving the below code to vimfiles/after/ftplugin/sql_snippets.vim.

* **$proc** - creates the skeleton for a TSQL stored procedure, including dropping the old procedure if it already exists.
* **$func** - creates the skeleton for a TSQL user-defined function (scalar), including dropping the old function if it already exists.
* **$view** - creates the skeleton for a TSQL view, including dropping the old view if it already exists.
* **$table** - creates the skeleton for a TSQL table, including dropping the old table if it already exists.
* **$sum** - creates a TSQL SUM statement using the specified field and creates an alias to preserve the field name.
* **$vc** - creates a varchar definition using the specified size.
* **$c** - creates a char definition using the specified size.
* **$d** - creates a decimal definition using the specified size and precision.
* **$tv** - creates a table variable definition.
* **$tt** - creates a temp table definition.


Copy this code and paste it in your HTML
  1. if !exists('loaded_snippet') || &cp
  2. finish
  3. endif
  4.  
  5. Snippet $proc IF EXISTS (<CR>SELECT 1 FROM INFORMATION_SCHEMA.ROUTINES<CR>
  6. \WHERE ROUTINE_NAME = '<{"name"}>'<CR>
  7. \AND ROUTINE_SCHEMA = 'dbo'<CR>AND ROUTINE_TYPE = 'PROCEDURE'<CR><BS>)<CR>
  8. \BEGIN<CR>DROP PROCEDURE dbo.<{"name"}><CR>
  9. \PRINT 'Dropped dbo.<{"name"}>'<CR>
  10. \END<CR>GO<CR><CR>CREATE PROCEDURE dbo.<{"name"}> (<CR>
  11. \/*<CR> Sample calls:<CR>
  12. \<BS><Tab>EXEC <{"name"}><CR><BS>*/<CR>)<CR>AS BEGIN<CR>
  13. \<Tab>SET NOCOUNT ON<CR><{}><CR>END<CR>GO<CR><CR>IF @@ERROR = 0<CR>
  14. \PRINT 'Created dbo.<{"name"}>'<CR><BS>GO<CR>
  15.  
  16. Snippet $func IF EXISTS (<CR>SELECT 1 FROM INFORMATION_SCHEMA.ROUTINES<CR>
  17. \WHERE ROUTINE_NAME = '<{"name"}>'<CR>
  18. \AND ROUTINE_SCHEMA = 'dbo'<CR>AND ROUTINE_TYPE = 'FUNCTION'<CR><BS>)<CR>
  19. \BEGIN<CR>DROP FUNCTION dbo.<{"name"}><CR>
  20. \PRINT 'Dropped dbo.<{"name"}>'<CR>
  21. \END<CR>GO<CR><CR>CREATE FUNCTION dbo.<{"name"}> (<CR>
  22. \/*<CR> Sample calls:<CR>
  23. \<BS><Tab>SELECT dbo.<{"name"}>()<CR><BS>*/<CR>)<CR>
  24. \RETURNS <{"return_type"}><CR>AS BEGIN<CR>
  25. \<Tab><{}><CR>END<CR>GO<CR><CR>IF @@ERROR = 0<CR>
  26. \PRINT 'Created dbo.<{"name"}>'<CR><BS>GO<CR>
  27.  
  28. Snippet $view IF EXISTS (SELECT 1 FROM INFORMATION_SCHEMA.VIEWS
  29. \WHERE TABLE_NAME = '<{"name"}>') BEGIN<CR>
  30. \DROP VIEW dbo.<{"name"}><CR>
  31. \PRINT 'Dropped dbo.<{"name"}>'<CR>
  32. \END<CR>GO<CR><CR>CREATE VIEW dbo.<{"name"}><CR>AS<CR>
  33. \/* Sample calls:<CR>
  34. \<Tab>SELECT * FROM <{"name"}><CR><BS>*/<CR><{}><CR>GO<CR>
  35. \<CR>IF @@ERROR = 0<CR>
  36. \PRINT 'Created dbo.<{"name"}>'<CR><BS>GO<CR>
  37.  
  38. Snippet $table IF EXISTS (<CR>SELECT 1 FROM INFORMATION_SCHEMA.TABLES<CR>
  39. \WHERE TABLE_NAME = '<{"name"}>'
  40. \AND TABLE_SCHEMA = 'dbo'<CR><BS>)<CR>BEGIN<CR>
  41. \DROP TABLE dbo.<{"name"}><CR>
  42. \PRINT 'Dropped dbo.<{"name"}>'<CR>
  43. \END<CR>GO<CR><CR>CREATE TABLE dbo.<{"name"}> (<CR>
  44. \<{}><CR>)<CR>GO<CR><CR>IF @@ERROR = 0<CR>
  45. \PRINT 'Created dbo.<{"name"}>'<CR><BS>GO<CR>
  46.  
  47. Snippet $sum SUM(<{"field"}>) AS <{"field"}>,<{}>
  48.  
  49. Snippet $vc varchar(<{"size"}>)<{}>
  50.  
  51. Snippet $c char(<{"size"}>)<{}>
  52.  
  53. Snippet $d decimal(<{"size"}>,<{"precision"}>)<{}>
  54.  
  55. Snippet $tv DECLARE @<{"name"}> table (<CR><{}><CR>)
  56.  
  57. Snippet $tt CREATE TABLE #<{"name"}> (<CR><{}><CR>)

URL: http://www.vim.org/scripts/script.php?script_id=1318

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.