What is the difference between CALL and EXEC in T-SQL?

前端 未结 3 634
忘掉有多难
忘掉有多难 2021-02-18 22:18

Consider:

CREATE PROCEDURE LowerCityDiscounts @city VARCHAR(45), @decrease DECIMAL(10,2) AS
BEGIN
    BEGIN TRANSACTION;
    UPDATE Customers SET discnt = discnt         


        
3条回答
  •  执笔经年
    2021-02-18 22:51

    The T-SQL language does not recognise ODBC escape sequences; EXEC is the only command available for calling a stored procedure. ODBC escape sequences are interpreted by client-side libraries (e.g. ODBC, OLE DB, ADO, ADO.NET) and translated to real T-SQL syntax on the fly before execution.

    The end result is, you can call your top-level stored procedure from the client using CALL if you want to, but if that procedure calls others, it must use EXEC.

    The same principle applies for the date/time literal escape sequences.

提交回复
热议问题