SQL Server: T-SQL Alternative to 'CREATE OR REPLACE' in PL/SQL
2012-06-12 16:31
561 查看
'CREATE OR REPLACE' SQL statement is used widely in PL/SQL (supported in Oracle, PostgreSQL, etc). It is very useful in SQL script files which help user to build up database objects.
But in T-SQL (supported in Microsoft SQL Server only), 'CREATE OR REPLACE' SQL statement is not supported. Till SQL Server 2012 being published, this statement is not supported yet. But if
you use 'Create procedure <procedure_name>' statement, you cannot execute for multiple times. As PL/SQL 'CREATE OR REPLACE' can be executed for multiple times, T-SQL 'Create procedure <procedure_name>'
seems not make sense.
However, can we improve the user experience of 'Create procedure <procedure_name>'? Yeah, of course we could.
Here is an example to show alternative of 'CREATE OR REPLACE' in T-SQL:
But in T-SQL (supported in Microsoft SQL Server only), 'CREATE OR REPLACE' SQL statement is not supported. Till SQL Server 2012 being published, this statement is not supported yet. But if
you use 'Create procedure <procedure_name>' statement, you cannot execute for multiple times. As PL/SQL 'CREATE OR REPLACE' can be executed for multiple times, T-SQL 'Create procedure <procedure_name>'
seems not make sense.
However, can we improve the user experience of 'Create procedure <procedure_name>'? Yeah, of course we could.
Here is an example to show alternative of 'CREATE OR REPLACE' in T-SQL:
SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO IF NOT EXISTS(select * from sys.procedures where name = 'sp_LinkMessage') EXEC sp_ExecuteSQL N'CREATE PROC dbo.sp_LinkMessage as RAISERROR(''dbo.sp_LinkMessage is incomplete'', 16, 127);'; GO -- ============================================= -- Author: Yaping Xin -- Create date: 2012.6.11 -- Description: link command message to function -- Modification: -- ============================================= ALTER PROCEDURE dbo.sp_LinkMessage @idFunction numeric(18,0), @idMessage numeric(18,0) AS BEGIN -- TODO -- END GO
相关文章推荐
- 如何找回被create or replace覆盖的PL/SQL对象
- 找回被create or replace覆盖的PL/SQL对象
- 如何找回被create or replace覆盖的PL/SQL对象
- Problem to create "New Database Diagram" in Microsoft SQL Server Management Studio for SQL Server 2012
- 在SQL Server中使用Hints测试索引(Using Hints To Test Indexes in SQL Server)
- How to create columns like "bigint" or "longtext" in Rails migrations
- ORA-14452: attempt to create, alter or drop an index on temporary table already in use
- ORA-14452: attempt to create, alter or drop an index on temporary table already in use
- "Your computer could not be joined to the domain. You have exceeded the maximum number of computer accounts you are allowed to create in this domain. Contact your system administrator to have this limit reset or increased."
- java.sql.SQLException: QueryRunner requires a DataSource to be invoked in this way, or a Connection
- Error in module : Call to Application.CreateForm is missing or incorrect.
- 使用Powerdesigner的物理数据模型生成SQL脚本中开头处多出来的create or replace package PDTypes
- ?? [SQL Server] -- Using FILESTREAM to Store BLOBs in the NTFS File System in SQL Server 2008
- How to create an Excel sheet or chart in VC?
- This function has none of Deterministic,no sql,or reads sql data in its declaration and binary logging is enabled(you *might* want to use the less safe log_bin_trust_function_creators variable
- pyspark sql createGlobalTempView和createOrReplaceTempView
- Uses DBMS_DDL.CREATE_WRAPPED to obfuscate PL/SQL source
- Using the Microsoft Access Providers to Replace the Built-In SQL Server Providers
- Create DDL table in SQL Server 2005 to audit DDL trigger activity
- In order to run a trace against SQL Server you must be a member of sysadmin fixed server role or have the ALTER TRACE permission.