0

I have a table that holds client informations

[ID] [int] IDENTITY(1,1) NOT NULL, // Primary Key
[Name] [varchar](50) NOT NULL,
[User] [varchar](50) NOT NULL,
[Adrss] [varchar](50) NOT NULL,
[Connected] [int] NOT NULL,

then i have a Stored Precedure

 procedure AddClient

    @Name Varchar(50),
    @User Varchar(50),
    @Adrss Varchar(50),
    @Connected Int

    as

        Insert into Clients(
        Name,
        User,
        Adrss,
        Connected)
        Values(
        @Name,
        @User,
        @adrss
        @Connected)

So The Field ID is auto increment I want to retreive it's value while inserting i want to return the insert position

Note 1 : I'm searching for another method than the Max(ID +1)

Note 2 : Please note that if any row is deleted the value will continue increment the Deleted ID won't be regenerated.

Jonnny
  • 4,939
  • 11
  • 63
  • 93
Left panda
  • 148
  • 2
  • 15

1 Answers1

0

Depends what DB you are using, if MySQL you can use http://php.net/manual/en/mysqli.insert-id.php for PHP

SCOPE_IDENTITY() Can be used for SQL-Server

Here is a good answer: https://stackoverflow.com/a/9477528/895169

Community
  • 1
  • 1
Jonnny
  • 4,939
  • 11
  • 63
  • 93