++ed by:

103 PAUSE user(s)
101 non-PAUSE user(s).

Peter Rabbitson
and 1 contributors


DBIx::Class::Storage::DBI::MSSQL - Base Class for Microsoft SQL Server support in DBIx::Class


This is the base class for Microsoft SQL Server support, used by DBIx::Class::Storage::DBI::ODBC::Microsoft_SQL_Server and DBIx::Class::Storage::DBI::Sybase::Microsoft_SQL_Server.


IDENTITY information

Microsoft SQL Server supports three methods of retrieving the IDENTITY value for inserted row: IDENT_CURRENT, @@IDENTITY, and SCOPE_IDENTITY(). SCOPE_IDENTITY is used here because it is the safest. However, it must be called is the same execute statement, not just the same connection.

So, this implementation appends a SELECT SCOPE_IDENTITY() statement onto each INSERT to accommodate that requirement.

SELECT @@IDENTITY can also be used by issuing:


it will only be used if SCOPE_IDENTITY() fails.

This is more dangerous, as inserting into a table with an on insert trigger that inserts into another table with an identity will give erroneous results on recent versions of SQL Server.

identity insert

Be aware that we have tried to make things as simple as possible for our users. For MSSQL that means that when a user tries to create a row, while supplying an explicit value for an autoincrementing column, we will try to issue the appropriate database call to make this possible, namely SET IDENTITY_INSERT $table_name ON. Unfortunately this operation in MSSQL requires the db_ddladmin privilege, which is normally not included in the standard write-permissions.


See "CONTRIBUTORS" in DBIx::Class.


You may distribute this code under the same terms as Perl itself.