SQL SERVER -- IDENTITY -- Part-10
IDENTITY:-
Identity Is a Auto Increment Number.
We no need to Insert Data into Identity Column in a Table.
/*
EXAMPLE */
IF EXISTS(SELECT * FROM sys.tables WHERE NAME ='TEST_IDENTITY')
BEGIN
DROP TABLE TEST_IDENTITY
END
CREATE TABLE TEST_IDENTITY
(
EMPID INT IDENTITY(1,1)
,EMPNAME VARCHAR(50)
,SAL MONEY
,LOC VARCHAR(50)
,GENDER CHAR(6)
,DEPTNO INT
)
-- ERROR
INSERT INTO TEST_IDENTITY(EMPID,EMPNAME ,SAL ,LOC,DEPTNO,GENDER)
VALUES(1,'BALA',50000,'BANGALORE',101,'M')
-- SUCCESS
INSERT INTO TEST_IDENTITY(EMPNAME ,SAL ,LOC,DEPTNO,GENDER)
VALUES('BALA',50000,'BANGALORE',101,'M')
SELECT * FROM TEST_IDENTITY
No comments:
Post a Comment