/ Published in: Other
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.
* **$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.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
if !exists('loaded_snippet') || &cp finish endif Snippet $proc IF EXISTS (<CR>SELECT 1 FROM INFORMATION_SCHEMA.ROUTINES<CR> \WHERE ROUTINE_NAME = '<{"name"}>'<CR> \AND ROUTINE_SCHEMA = 'dbo'<CR>AND ROUTINE_TYPE = 'PROCEDURE'<CR><BS>)<CR> \BEGIN<CR>DROP PROCEDURE dbo.<{"name"}><CR> \PRINT 'Dropped dbo.<{"name"}>'<CR> \END<CR>GO<CR><CR>CREATE PROCEDURE dbo.<{"name"}> (<CR> \/*<CR> Sample calls:<CR> \<BS><Tab>EXEC <{"name"}><CR><BS>*/<CR>)<CR>AS BEGIN<CR> \<Tab>SET NOCOUNT ON<CR><{}><CR>END<CR>GO<CR><CR>IF @@ERROR = 0<CR> \PRINT 'Created dbo.<{"name"}>'<CR><BS>GO<CR> Snippet $func IF EXISTS (<CR>SELECT 1 FROM INFORMATION_SCHEMA.ROUTINES<CR> \WHERE ROUTINE_NAME = '<{"name"}>'<CR> \AND ROUTINE_SCHEMA = 'dbo'<CR>AND ROUTINE_TYPE = 'FUNCTION'<CR><BS>)<CR> \BEGIN<CR>DROP FUNCTION dbo.<{"name"}><CR> \PRINT 'Dropped dbo.<{"name"}>'<CR> \END<CR>GO<CR><CR>CREATE FUNCTION dbo.<{"name"}> (<CR> \/*<CR> Sample calls:<CR> \<BS><Tab>SELECT dbo.<{"name"}>()<CR><BS>*/<CR>)<CR> \RETURNS <{"return_type"}><CR>AS BEGIN<CR> \<Tab><{}><CR>END<CR>GO<CR><CR>IF @@ERROR = 0<CR> \PRINT 'Created dbo.<{"name"}>'<CR><BS>GO<CR> Snippet $view IF EXISTS (SELECT 1 FROM INFORMATION_SCHEMA.VIEWS \WHERE TABLE_NAME = '<{"name"}>') BEGIN<CR> \DROP VIEW dbo.<{"name"}><CR> \PRINT 'Dropped dbo.<{"name"}>'<CR> \END<CR>GO<CR><CR>CREATE VIEW dbo.<{"name"}><CR>AS<CR> \/* Sample calls:<CR> \<Tab>SELECT * FROM <{"name"}><CR><BS>*/<CR><{}><CR>GO<CR> \<CR>IF @@ERROR = 0<CR> \PRINT 'Created dbo.<{"name"}>'<CR><BS>GO<CR> Snippet $table IF EXISTS (<CR>SELECT 1 FROM INFORMATION_SCHEMA.TABLES<CR> \WHERE TABLE_NAME = '<{"name"}>' \AND TABLE_SCHEMA = 'dbo'<CR><BS>)<CR>BEGIN<CR> \DROP TABLE dbo.<{"name"}><CR> \PRINT 'Dropped dbo.<{"name"}>'<CR> \END<CR>GO<CR><CR>CREATE TABLE dbo.<{"name"}> (<CR> \<{}><CR>)<CR>GO<CR><CR>IF @@ERROR = 0<CR> \PRINT 'Created dbo.<{"name"}>'<CR><BS>GO<CR> Snippet $sum SUM(<{"field"}>) AS <{"field"}>,<{}> Snippet $vc varchar(<{"size"}>)<{}> Snippet $c char(<{"size"}>)<{}> Snippet $d decimal(<{"size"}>,<{"precision"}>)<{}> Snippet $tv DECLARE @<{"name"}> table (<CR><{}><CR>) Snippet $tt CREATE TABLE #<{"name"}> (<CR><{}><CR>)
URL: http://www.vim.org/scripts/script.php?script_id=1318