SQL snippets

sql

Copy all rows from one table to another

insert into stateNew ([state], [abbrev])
select * from States

Getting identity column from last row added with a stored procedure

Stored procedure:

CREATE PROCEDURE [dbo].[qInsert]
    @Id int,
    @Name nvarchar(100)
AS
BEGIN
    SET NOCOUNT ON
    INSERT INTO [dbo].[artist]
    (
        [Name]
    )
    VALUES(
        @Name
    );
    RETURN SCOPE_IDENTITY();
END
GO
EXEC @rp = qInsert 0, 'Bobby Fuller Four'
SELECT @rp as 'identify'