Tutorial by Examples

CREATE TABLE dbo.logging_table(log_id INT IDENTITY(1,1) PRIMARY KEY, log_message VARCHAR(255)) CREATE TABLE dbo.person(person_id INT IDENTITY(1,1) PRIMARY KEY, person_name VARCHAR(100) NOT NULL) GO; CREATE TRIGGER dbo.InsertToADiffere...
CREATE TABLE dbo.logging_table(log_id INT IDENTITY(1,1) PRIMARY KEY, log_message VARCHAR(255)) CREATE TABLE dbo.person(person_id INT IDENTITY(1,1) PRIMARY KEY, person_name VARCHAR(100) NOT NULL) GO; CREATE TRIGGER dbo.InsertToADiffere...
SELECT IDENT_CURRENT('dbo.person'); This will select the most recently-added identity value on the selected table, regardless of connection or scope.
SELECT MAX(Id) FROM Employees -- Display the value of Id in the last row in Employees table. GO INSERT INTO Employees (FName, LName, PhoneNumber) -- Insert a new row VALUES ('John', 'Smith', '25558696525') GO SELECT @@IDENTITY GO SELECT MAX(Id) FROM Employees -- Display the value of Id...

Page 1 of 1