Some SQL Statments (Up-to-date)

1- To Get the Last Record in table name test for Example With columns ( testId,testName )

then write the select statment :

SELECT testid,testName FROM test WHERE testid=( SELECT MAX( testid ) FROM test )

you can also use the Following statment :

SELECT Top 1 testid,testName FROM test ORDER BY testid DESC

2- To copy tables From Database To other :

SELECT   * into TargetTable
FROM        hrdb.dbo.SourceTable

we want to copy the table hrEmployees from the database HR to Created Table tblEmployees in Accounting Database for Example:

SELECT   * into tblEmployees
FROM        hrdb.dbo.hrEmployees