Skip to main content

Posts

Showing posts with the label SQL Server Column Alias

What is @@RowCount in SQL? What does this statement do @@RowCount?

The  @@ROWCOUNT  is a special variable of SQL. It will return the number of rows changed by the last statement. The @@RowCount is equal to (=) the number of rows changed by the last statement. Syntax : - @@ROWCOUNT Return Types : - INT What is the scope of @@RowCount? The @@RowCount is both the scope and connection safe and it is read only! For example as, -- DECLARE RETURN TABLE DECLARE @Return_Table TABLE (Code varchar ( 10 ) ,Message varchar ( 100 ), ID varchar ( 100 )) --UPDATE CUSTOMER QUERY UPDATE Customer SET Name = N 'Anil Singh' WHERE Id = 0786 --USE OF @@ROWCOUNT IF (@@ROWCOUNT > 0 ) BEGIN INSERT INTO @Return_Table (Code, Message, ID) SELECT 'OK' , 'SUCCESS' , SCOPE_IDENTITY() SELECT Code, Message, ID FROM @Return_Table END ELSE BEGIN INSERT INTO @Return_Table (Code, Message, ID) SELECT 'ERROR' , 'Warning - No rows updated.' , SCOPE_IDENTITY() SELECT Code, Message, ID FROM @R...

T-SQL Columns, Tables Alias

In SQL, we can alias columns, views and tables. A table alias is also called a co-relation name. It is a temporarily names of columns or tables. The Alias temporarily assigns another name to a column, or table at the time of a SELECT query and the assigning alias doesn’t rename the column or table name actually! Basically, it make column, or table more readable to the programmers. Syntax: --USE OF TABLE ALIAS SELECT TBL . Id , TBL . Name FROM [dbo].[Tbl_Demo] AS TBL WHERE TBL . Id in ( 1 , 2 , 3 ) --USE OF COLUMN ALIAS SELECT TBL . Id AS UID, TBL . Name AS UNAME FROM [dbo].[Tbl_Demo] AS TBL WHERE TBL . Id in ( 1 , 2 , 3 )