You must Sign In to post a response.
  • Category: SQL Server

    What use an dwhere we use @ , # , @@


    Can anyone explain me the meaning of @,#,@@ and where we use thwm in sql ...

  • #648711
    Hi divya

    1. @ is used to declare variables in stored procedures
    2. @@ is used to declare identity column
    3. # is used to declare or create temporary tables in sql

  • #648719
    @ is used to represent a local variable in sql server

    It may be a variable and also a parameter to a procedure or a user defined function

    We can also declare a table variable using @ symbol

    @@ is used to represent a global variable

    for example:

    SELECT @@error would give the errror

    SELECT @@connections would give the connections

    SELECT @@ROWCOUNT would give the count of rows affected in the last transaction

    # is used to represent a local temporary table

    Please mark this as Answer, if this helps

    Alwyn Duraisingh.M 
    << Database Administrator >>
    Jesus saves! The rest of us better make backups...

  • #648745
    @ is used for variables. You used it in parameters coming in on a stored procedure. You can declare local variables "Declare @cnt as int" You can also declare table variables.

    @@:It means it's a global variable.

    # :represent a local temporary table

    e.g.drop table #t_source

    Software Engg.

  • #648858
    Hi Divya,

    We use @ to declare variables in sql server,

    declare @Status varchar(50)

    # while creating temporary tables,

    create table #temp1([ID] int,[Name] varchar(102))

    @@ for global access specifier.
    Ex:Mostly we use in cursors

    DECLARE Sample_Cursor CURSOR FOR
    SELECT ID FROM sampleTable;
    OPEN Sample_Cursor;
    FETCH NEXT FROM Sample_Cursor;
    While @@FETCH_STATUS = 0

    Ex: We executes FETCH from one cursor, and then calling a stored procedure that opens and processes the results from another cursor. When control is returned from the called stored procedure, @@FETCH_STATUS reflects the last FETCH executed in the stored procedure, not the FETCH statement executed before the stored procedure is called.

    Hope this will give you some idea.

    Never lose hope..You never know what tomorrow will bring

  • This thread is locked for new responses. Please post your comments and questions as a separate thread.
    If required, refer to the URL of this page in your new post.