Landscape �ȥåץڡ��� | < ������ 2005-05-20 2005-05-23 ������ 2005-05-25 >

Landscape - ���󥸥˥��Υ�� 2005-05-23

IDENT_CURRENT / @@IDENTITY / SCOPE_IDENTITY �ΰ㤤


<!drk7jp_parse_scope>

* IDENT_CURRENT / @@IDENTITY / SCOPE_IDENTITY �ΰ㤤

���ε�����ľ���URL: Permlink | ���ε�����°���륫�ƥ���: [MS SQL Server]

MS SQL Server2000 �� IDENTITY ���ͼ����ˤĤ��ƤΥ�⡣IDENTITY �� 2003-05-13 �Ρ�MS SQL Server �Υ������󥹷��פǽ񤤤��褦�ˡ�Ϣ�֤Ȥ�������դ� ID �� DB ¦�ǿ���Ф�����λ��Ȥߡ�

- ������IDENT_CURRENT @@IDENTITY SCOPE_IDENTITY �������̻Ȥ�ʬ��

IDENT_CURRENT @@IDENTITY SCOPE_IDENTITY �ΰ㤤 �ˤĤ��ơ������̤˥�⡣

�ȥꥬ���ʤɤ� INSERT ���줿�ͤ�ޤ᤿����Υơ��֥���ͤ��ꤿ���Ȥ��� IDENT_CURRENT��
�ȥꥬ���ʤɤ� INSERT ���줿�ͤ�ޤ�Ƽ�ꤿ���Ȥ��� @@IDENTITY��
�ȥꥬ���ʤɤ� INSERT ���줿�ͤ�����Ƽ�ꤿ���Ȥ��� SCOPE_IDENTITY��

- IDENT_CURRENT �Υ�ե���󥹤Ϥ狼��ˤ���

��ե���󥹤��������ɤ�������ˤ狼��ˤ�������Ǥ�դΥ��å����פȤ���ͭ���ϰ���פȤ��������ʤ��Ǥ����ʤ�Ȥ��Ƥ�����դФ��ꡣǤ�դäơ�ï�ΰջ֤�ȿ�Ǥ���Ƥ��? ��ɲ���ؤ��Ƥ���Τ����äѤ�狼��ʤ���

Transact-SQL ��ե���� IDENT_CURRENT
http://www.microsoft.com/japan/msdn/library/ja/tsqlref/ts_ia ...
IDENT_CURRENT �ϡ�Ǥ�դΥ��å�����ͭ���ϰ��������Υơ��֥���Ф����������줿�Ǹ�� ID �ͤ��֤��ޤ���
@@IDENTITY �ϡ����٤Ƥ�ͭ���ϰϤ��оݤˡ����ߤΥ��å�������Ǥ�դΥơ��֥���Ф����������줿�Ǹ�� ID �ͤ��֤��ޤ���
SCOPE_IDENTITY �ϡ����ߤΥ��å����ȸ��ߤ�ͭ���ϰ����Ǥ�դΥơ��֥���Ф����������줿�Ǹ�� ID �ͤ��֤��ޤ���

��ʸ���⸶ʸ�������狼��䤹���󤸤�ʤ����Ȼפä��Τǡ��Ѹ��Ǥ򸫤Ƥߤ롣

Transact-SQL Reference IDENT_CURRENT
http://msdn.microsoft.com/library/en-us/tsqlref/ts_ia-iz_82i ...
IDENT_CURRENT returns the last identity value generated for a specific table in any session and any scope.
@@IDENTITY returns the last identity value generated for any table in the current session, across all scopes.
SCOPE_IDENTITY returns the last identity value generated for any table in the current session and the current scope.

�Ѹ�ǽ񤫤줿�����狼��䤹������Ǥ�աפä� any ���ä��Τ���all ������ơפ������ΤϤޤ��������ɡ�

IDENT_CURRENT �ϰ����ǻ��ꤷ������Υơ��֥�ˤĤ��Ƥ��͡������å�������������ס�
@@IDENTITY �����ƤΥơ��֥롢���ߤΥ��å�������ƤΥ������ס�
SCOPE_IDENTITY �����ƤΥơ��֥롢���ߤΥ��å���󡢸��ߤΥ������ס�

- Transact-SQL ��ե���� IDENT_CURRENT

�㤬����Τϴ򤷤����ɡ���äѤ�狼��ˤ���������İ���ɤ���������⡢�Ѹ�Υɥ�����Ȥ��ɤ�������狼��䤹����

IDENT_CURRENT

Ǥ�դΥ��å�����ͭ���ϰ��������Υơ��֥���Ф����������줿 ID �ͤ��֤��ޤ���

��ʸ
IDENT_CURRENT('table_name')

����
table_name

ID �ͤ��֤����ơ��֥��̾���Ǥ���table_name �� varchar �Ǥ��ꡢ�����ͤϤ���ޤ���

����ͤη�
sql_variant

����
IDENT_CURRENT �ϡ�MicrosoftR SQL Server? 2000 �� ID �ؿ��Ǥ��� SCOPE_IDENTITY �� @@IDENTITY �˻��Ƥ��ޤ���3 �Ĥδؿ��Ȥ⡢�Ǹ���������줿 ID �ͤ��֤��ޤ������������ƴؿ�����ǡ�"�Ǹ�" ����������ͭ���ϰϤȥ��å���󤬤��줾��ۤʤ�ޤ���

IDENT_CURRENT �ϡ�Ǥ�դΥ��å�����ͭ���ϰ��������Υơ��֥���Ф����������줿�Ǹ�� ID �ͤ��֤��ޤ���


@@IDENTITY �ϡ����٤Ƥ�ͭ���ϰϤ��оݤˡ����ߤΥ��å�������Ǥ�դΥơ��֥���Ф����������줿�Ǹ�� ID �ͤ��֤��ޤ���


SCOPE_IDENTITY �ϡ����ߤΥ��å����ȸ��ߤ�ͭ���ϰ����Ǥ�դΥơ��֥���Ф����������줿�Ǹ�� ID �ͤ��֤��ޤ���
��
������Ǥϡ�IDENT_CURRENT��@@IDENTITY������� SCOPE_IDENTITY �����줾��ۤʤ� ID �ͤ��֤��ޤ���

USE pubs
DROP TABLE t6
DROP TABLE t7
GO
CREATE TABLE t6(id int IDENTITY)
CREATE TABLE t7(id int IDENTITY(100,1))
GO
CREATE TRIGGER t6ins ON t6 FOR INSERT
AS
BEGIN
  INSERT t7 DEFAULT VALUES
END
GO
--end of trigger definition

SELECT  * FROM t6
--id is empty.

SELECT  * FROM t7
--id is empty.

--Do the following in Session 1
INSERT t6 DEFAULT VALUES
SELECT @@IDENTITY
/*Returns the value 100, which was inserted by the trigger.*/

SELECT SCOPE_IDENTITY()
/* Returns the value 1, which was inserted by the
INSERT stmt 2 statements before this query.*/

SELECT IDENT_CURRENT('t7')
/* Returns value inserted into t7, i.e. in the trigger.*/

SELECT IDENT_CURRENT('t6')
/* Returns value inserted into t6, which was the INSERT statement 4 stmts before this query.*/

-- Do the following in Session 2
SELECT @@IDENTITY
/* Returns NULL since there has been no INSERT action
so far in this session.*/

SELECT SCOPE_IDENTITY()
/* Returns NULL since there has been no INSERT action
so far in this scope in this session.*/

SELECT IDENT_CURRENT('t7')
/* Returns the last value inserted into t7.*/


<!/drk7jp_parse_scope>
���٤Ƥε����θ��Ф� (��1029��)
�����ƥ���ΰ����ȵ����ο�
���ƥ��ꤴ�Ȥ˵�����ޤȤ��ɤߤǤ��ޤ���������ɽ������򸫤������ϡ����٤Ƥε����θ��Ф� (���ƥ�����ɽ��) �ء�

ľ��30��ʬ�ε���
2007-04-23 (Mon)
2007-03-07 (Wed)
2007-02-27 (Tue)
2007-01-17 (Wed)
2007-01-15 (Mon)
2007-01-14 (Sun)
2007-01-08 (Mon)
2006-12-01 (Fri)
2006-11-22 (Wed)
2006-11-20 (Mon)
2006-11-19 (Sun)
2006-09-30 (Sat)
2006-08-29 (Tue)
2006-08-04 (Fri)
2006-07-27 (Thu)
2006-07-23 (Sun)
2006-07-17 (Mon)
2006-07-10 (Mon)
2006-07-06 (Thu)
2006-07-03 (Mon)
2006-06-29 (Thu)
2006-06-28 (Wed)
2006-06-27 (Tue)
2006-06-25 (Sun)
2006-06-19 (Mon)
2006-06-18 (Sun)
2006-06-15 (Thu)
2006-06-11 (Sun)
2006-06-01 (Thu)
2006-05-30 (Tue)
�ץ��ե�����
��ƣ ���������󥸥˥��Ǥ������ԵܻԤ˽���Ǥ��ޤ���
���
RSS
���ݥ󥵡��ɥ��
Powered by
�������饤�󥿡��ͥå���

��� ��ƣ ���� Saito Hiroaki Gmail Address
Landscape - ���󥸥˥��Υ�� http://sonic64.com/
Landscape �����ɥ����������ɤߤޤ���
�Ҥ餬�ʤ��� ���ɤ������� �Ǥ���