SQL Server's SET NOCOUNT ON Postgresql equivalent [closed] - sql

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
I've to help migrating a SQL Server 2008 database to a PostgreSQL 9.4.10 one. The original querys have SET NOCOUNT ON and SET NOCOUNT OFF several times, and I can't change this fact so ignoring the number of rows affected isn't a solution. That's why I need to find an equivalent to this statement, but all I can find are really old posts where they say I should ignore the result. Any ideas? Thanks.
EDIT: these SET NOCOUNTare inside a stored procedure that goes like this:
CREATE PROCEDURE [procedureName]
Declares
--Variables
WITH ENCRYPTION
AS
SET NOCOUNT ON
--Procedure's code
SET NOCOUNT OFF
GO
As I've said this code isn't mine, so I can't post any of it more than the source of my doubt.

Related

Why there could be only one create statement in one batch in T-SQL? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 3 years ago.
Improve this question
What's the reasoning behind this design decision?
Why there could be only one create statement in one batch in T-SQL?
The limitations about which statements can be combined in a batch, and which statements must be the first statement in a batch are technical limitations of the TSQL parser. There's no "good" reason for them; as the language evolved over the many versions balancing introducing new syntax while maintaining backwards compatibility introduced some quirks in the language like this. The requirement to terminate the statement before a CTE with ';' is another similar quirk.
The typical workaround for this is to push the DDL statement into a nested batch. EG:
declare #sql1 nvarchar(max) = '
create schema foo;
'
declare #sql2 nvarchar(max) = '
create table foo.bar(id int);
'
exec (#sql1)
exec (#sql2)

We can go for transaction management in procedure but we can’t go in function? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
We can go for transaction management in procedure but we can’t go in function, I have seen this statement at multiple places, while we ask for difference between function & procedure, But I did below test in oracle and **I can see its working fine for function also**. Can anybody please let me know what thing am I missing about above statement, because this statement looks completely wrong to me?
select * from test; *(test table having single column "name varchar(2)")
create or replace function FUNTest
return number as result NUMBER(6,2);
BEGIN
SAVEPOINT fn_fntest;
insert into test(NAME) values('Dinesh');
ROLLBACK TO fn_fntest;
return 1;
END;
/
Begin
DBMS_OUTPUT.PUT_LINE(FUNTest());
end;
/
Purpose of function is different from procedure.
Function: Supposed to do some calculation and return some value(most
of the cases)
Procedure: Perform some operation based on data/column.It manages transaction as well, because you will definately be storing new data somewhere.
Now talking about transaction management in function, well it depends on calling mechanism of function.
If your function is having transactional statement like commit/rollback then it should be called from some other block which is capable of handling transaction like procedure or anonymous block(your case).
If you call that same function from select statement like "select funtest() from dual;" then you will get error as select statement is not capable of opening transaction.
If you still want to call any function having transactional statement from non-transactional body(select statement) then your function should be capable of opening separate independent transaction(PRAGMA AUTONOMOUS_TRANSACTION).
Please refer to http://www.datacoons.com/content/transaction.php for more information on transaction management.

SQL Query behaving weird [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
Below queries in sql giving weird results. Please help me to understand why it is happening.
exec sp_executesql N'SP_MNP_DownLoadFiles #FileTypeId,#UserId',N'#FileTypeId smallint,#UserId bigint',#FileTypeId=2,#UserId=18 -- This query returns nothing
Exec SP_MNP_DownLoadFiles #FileTypeId=2,#UserId=18 -- This query returns some result
Select Type as FileTypeId ,FileStream as Attachment FROM MNPFiles
where CustomerId = 18
AND
Type = 2 -- This is the query inside SP.
Please consider the data types are same everywhere.
What I am doing wrong here?
Your dynamic SQL string doesn't match your non-dynamic statement.
exec sp_executesql N'EXEC SP_MNP_DownLoadFiles ...',...
^^^^
Other things to check:
Other SELECTs in your stored procedure prior to your main one. You may need to SET NOCOUNT ON.
That you're not RETURNing something before your main query

Recommended SP/method to gain information [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
When I need more information about table and its column I always use the build-in stored procedure 'sp_help xxxxx' to retrieve more information.
What other method or SP are usable to use?
You can use sp_depends to get want tables and columns it is using
EXEC sp_depends yourProcedure;
I prefer to use dynamic management views (DMV) and functions (DMF) to get more information about database server..........The DMV/DMF's have been organized into the following different groups:
Common Language Runtime related
Database Mirroring related
Execution related
Full-Text Search related
Index related
I/O related
Query Notifications related
Replication related
Service Broker related
SQL Server Operation system
Transaction related
Just browsing to the table in SQL Server Management Studio will tell you quite a lot.
Table/Column definitions.
Indexes
Triggers
Constraints
Primary/Foreign Keys
Dependancies
etc, etc
Look into the sysobjects view (http://msdn.microsoft.com/en-us/library/ms177596.aspx):
SELECT * FROM sysobjects WHERE type = 'P'
Other sys view can be handy too.
How about using sp_columns
EXEC sp_columns #table_name = N'TableName'
Using sp_helptext will come in handy, it gives you the definition of a stored procedure, function or view.
I.E.:
CREATE PROC usp_MyProcedure AS SELECT * FROM TABLE
Runing the following will output the query above.
Exec sp_helptext 'usp_MyProcedure'

Usage of SET NOCOUNT ON [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
SET NOCOUNT ON usage
Why do we use the below statement in Triggers and stored procedures?
SET NOCOUNT ON
Could any one explain me please? I have gone through the similar question posted before. But as I am new learning SQL, I am unable to understand their discussion.
When SET NOCOUNT is ON, the count (indicating the number of rows affected by a Transact-SQL statement) is not returned. When SET NOCOUNT is OFF, the count is returned.
So if you do an UPDATE query (for example) the query will not return the affected rows.
for more information check out => http://msdn.microsoft.com/en-us/library/aa259204(v=sql.80).aspx