Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

Michel http://michelc.wordpress.com/

« Newer Snippets
Older Snippets »
Showing 1-3 of 3 total  RSS 

SqlServer table structure with Information_Schema

SELECT COLUMN_NAME,
       DATA_TYPE,
       CHARACTER_MAXIMUM_LENGTH,
       NUMERIC_PRECISION,
       NUMERIC_SCALE,
       IS_NULLABLE,
       COLUMNPROPERTY(OBJECT_ID(TABLE_NAME), COLUMN_NAME, 'IsIdentity') AS IS_AUTOINCREMENT,
       COLUMN_DEFAULT
FROM   INFORMATION_SCHEMA.COLUMNS
WHERE  TABLE_NAME = 'xxxxxxxx'
ORDER BY ORDINAL_POSITION

Edit: The "system_function_schema.fn_datadictionary" snippet will create a system function in SQL Server that returns a data dictionary for any database on the server (http://www.bigbold.com/snippets/posts/show/1175).

Define Identity value for SqlServer

SET IDENTITY_INSERT MyTable ON;
INSERT INTO MyTable
    (MyIdentityField, MyFirstField, MySecondField)
VALUES
    (12345, 'ABCDE', 'etc...');
SET IDENTITY_INSERT MyTable OFF;

Literal DateTime for SqlServer

CONVERT(DATETIME, 'yyyymmdd', 112)

112 -> ISO date
cf. http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tsqlref/ts_ca-co_2f3o.asp
----------
Edit: a better solution !
{d 'yyyy-mm-dd'}

Thanks to Wild Richard (http://www.bigbold.com/snippets/posts/show/756)
« Newer Snippets
Older Snippets »
Showing 1-3 of 3 total  RSS