17.06.2013 Views

Beginning Microsoft SQL Server 2008 ... - S3 Tech Training

Beginning Microsoft SQL Server 2008 ... - S3 Tech Training

Beginning Microsoft SQL Server 2008 ... - S3 Tech Training

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

If you’re using identity columns and then referencing them as a foreign key in another table, you’ll find<br />

yourself using this one all the time. You can create the parent record (usually the one with the identity<br />

you need to retrieve), then select @@IDENTITY to know what value you need to relate child records to.<br />

If you perform inserts into multiple tables with identity values, remember that the value in @@IDENTITY<br />

will only be for the last identity value inserted — anything before that will have been lost, unless you<br />

move the value into a holding variable after each insert. Also, if the last column you inserted into didn’t<br />

have an identity column, then @@IDENTITY will be set to NULL.<br />

IDENTITY<br />

The IDENTITY function is used to insert an identity column into a new table. It is used only with a<br />

SELECT statement with an INTO table clause. The syntax is as follows:<br />

Where:<br />

ISNULL<br />

IDENTITY([, , ]) AS <br />

❑ data type is the data type of the identity column.<br />

❑ seed is the value to be assigned to the first row in the table. Each subsequent row is assigned<br />

the next identity value, which is equal to the last IDENTITY value plus the increment value. If<br />

neither seed nor increment is specified, both default to 1.<br />

❑ increment is the increment to add to the seed value for successive rows in the table.<br />

❑ column name is the name of the column that is to be inserted into the new table.<br />

The ISNULL function checks an expression for a NULL value and replaces it with a specified replacement<br />

value. The syntax is as follows:<br />

ISNULL(, )<br />

ISNUMERIC<br />

The ISNUMERIC function determines whether an expression is a valid numeric type. The syntax is as follows:<br />

NEWID<br />

ISNUMERIC()<br />

The NEWID function creates a unique value of type uniqueidentifier. The syntax is as follows:<br />

NEWID()<br />

Apendix A: System Functions<br />

643

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!