Home All Groups Group Topic Archive Search About

Sys Tables for Datetime type

Author
2 Sep 2005 6:33 PM
wnfisba
I am looking for a specific Datetime column and I don't know what table it
resides in.

How can I query the systables looking for all those columns with Datetime
type???

Thank You!

Author
2 Sep 2005 6:49 PM
Alejandro Mesa
Use the view information_schema.columns instead.

select
    table_schema,
    table_name,
    ordinal_position,
    column_name,
    data_type
from
    information_schema.columns
where
    data_type = 'datetime'
    and objectproperty(object_id(quotename(table_schema) + '.' +
quotename(table_name)), 'IsUserTable') = 1
    and objectproperty(object_id(quotename(table_schema) + '.' +
quotename(table_name)), 'IsMSShipped') = 0
order by
    table_schema,
    table_name,
    ordinal_position


AMB
Show quote
"wnfisba" wrote:

> I am looking for a specific Datetime column and I don't know what table it
> resides in.
>
> How can I query the systables looking for all those columns with Datetime
> type???
>
> Thank You!
Author
2 Sep 2005 6:59 PM
Aaron Bertrand [SQL Server MVP]
Just a couple of things,

(a) upper case (e.g. INFORMATION_SCHEMA.COLUMNS) should be used as opposed
to lower case, so that code will work equally well on case sensitive
collations.

(b) I would probably use DATA_TYPE IN ('DATETIME', 'SMALLDATETIME') because,
while not explicitly specified, the OP may not care if the column is
SMALL(DATETIME), may not know which datetime type it actually is, or may not
even know the difference.

A




Show quote
"Alejandro Mesa" <AlejandroM***@discussions.microsoft.com> wrote in message
news:BEC6B9ED-970C-4C35-AB7B-0D8C14738734@microsoft.com...
> Use the view information_schema.columns instead.
>
> select
> table_schema,
> table_name,
> ordinal_position,
> column_name,
> data_type
> from
> information_schema.columns
> where
> data_type = 'datetime'
> and objectproperty(object_id(quotename(table_schema) + '.' +
> quotename(table_name)), 'IsUserTable') = 1
>  and objectproperty(object_id(quotename(table_schema) + '.' +
> quotename(table_name)), 'IsMSShipped') = 0
> order by
> table_schema,
> table_name,
> ordinal_position
>
>
> AMB
> "wnfisba" wrote:
>
>> I am looking for a specific Datetime column and I don't know what table
>> it
>> resides in.
>>
>> How can I query the systables looking for all those columns with Datetime
>> type???
>>
>> Thank You!
Author
2 Sep 2005 7:08 PM
wnfisba
We don't have this view INFORMATION_SCHEMA. Do I have to build that view???

Show quote
"Aaron Bertrand [SQL Server MVP]" wrote:

> Just a couple of things,
>
> (a) upper case (e.g. INFORMATION_SCHEMA.COLUMNS) should be used as opposed
> to lower case, so that code will work equally well on case sensitive
> collations.
>
> (b) I would probably use DATA_TYPE IN ('DATETIME', 'SMALLDATETIME') because,
> while not explicitly specified, the OP may not care if the column is
> SMALL(DATETIME), may not know which datetime type it actually is, or may not
> even know the difference.
>
> A
>
>
>
>
> "Alejandro Mesa" <AlejandroM***@discussions.microsoft.com> wrote in message
> news:BEC6B9ED-970C-4C35-AB7B-0D8C14738734@microsoft.com...
> > Use the view information_schema.columns instead.
> >
> > select
> > table_schema,
> > table_name,
> > ordinal_position,
> > column_name,
> > data_type
> > from
> > information_schema.columns
> > where
> > data_type = 'datetime'
> > and objectproperty(object_id(quotename(table_schema) + '.' +
> > quotename(table_name)), 'IsUserTable') = 1
> >  and objectproperty(object_id(quotename(table_schema) + '.' +
> > quotename(table_name)), 'IsMSShipped') = 0
> > order by
> > table_schema,
> > table_name,
> > ordinal_position
> >
> >
> > AMB
> > "wnfisba" wrote:
> >
> >> I am looking for a specific Datetime column and I don't know what table
> >> it
> >> resides in.
> >>
> >> How can I query the systables looking for all those columns with Datetime
> >> type???
> >>
> >> Thank You!
>
>
>
Author
2 Sep 2005 7:29 PM
Alejandro Mesa
Can you load QA and execute "select @@version" and post the result.


AMB

Show quote
"wnfisba" wrote:

> We don't have this view INFORMATION_SCHEMA. Do I have to build that view???
>
> "Aaron Bertrand [SQL Server MVP]" wrote:
>
> > Just a couple of things,
> >
> > (a) upper case (e.g. INFORMATION_SCHEMA.COLUMNS) should be used as opposed
> > to lower case, so that code will work equally well on case sensitive
> > collations.
> >
> > (b) I would probably use DATA_TYPE IN ('DATETIME', 'SMALLDATETIME') because,
> > while not explicitly specified, the OP may not care if the column is
> > SMALL(DATETIME), may not know which datetime type it actually is, or may not
> > even know the difference.
> >
> > A
> >
> >
> >
> >
> > "Alejandro Mesa" <AlejandroM***@discussions.microsoft.com> wrote in message
> > news:BEC6B9ED-970C-4C35-AB7B-0D8C14738734@microsoft.com...
> > > Use the view information_schema.columns instead.
> > >
> > > select
> > > table_schema,
> > > table_name,
> > > ordinal_position,
> > > column_name,
> > > data_type
> > > from
> > > information_schema.columns
> > > where
> > > data_type = 'datetime'
> > > and objectproperty(object_id(quotename(table_schema) + '.' +
> > > quotename(table_name)), 'IsUserTable') = 1
> > >  and objectproperty(object_id(quotename(table_schema) + '.' +
> > > quotename(table_name)), 'IsMSShipped') = 0
> > > order by
> > > table_schema,
> > > table_name,
> > > ordinal_position
> > >
> > >
> > > AMB
> > > "wnfisba" wrote:
> > >
> > >> I am looking for a specific Datetime column and I don't know what table
> > >> it
> > >> resides in.
> > >>
> > >> How can I query the systables looking for all those columns with Datetime
> > >> type???
> > >>
> > >> Thank You!
> >
> >
> >
Author
2 Sep 2005 7:08 PM
wnfisba
We don't have this view INFORMATION_SCHEMA. Do I have to build that view???

Show quote
"Aaron Bertrand [SQL Server MVP]" wrote:

> Just a couple of things,
>
> (a) upper case (e.g. INFORMATION_SCHEMA.COLUMNS) should be used as opposed
> to lower case, so that code will work equally well on case sensitive
> collations.
>
> (b) I would probably use DATA_TYPE IN ('DATETIME', 'SMALLDATETIME') because,
> while not explicitly specified, the OP may not care if the column is
> SMALL(DATETIME), may not know which datetime type it actually is, or may not
> even know the difference.
>
> A
>
>
>
>
> "Alejandro Mesa" <AlejandroM***@discussions.microsoft.com> wrote in message
> news:BEC6B9ED-970C-4C35-AB7B-0D8C14738734@microsoft.com...
> > Use the view information_schema.columns instead.
> >
> > select
> > table_schema,
> > table_name,
> > ordinal_position,
> > column_name,
> > data_type
> > from
> > information_schema.columns
> > where
> > data_type = 'datetime'
> > and objectproperty(object_id(quotename(table_schema) + '.' +
> > quotename(table_name)), 'IsUserTable') = 1
> >  and objectproperty(object_id(quotename(table_schema) + '.' +
> > quotename(table_name)), 'IsMSShipped') = 0
> > order by
> > table_schema,
> > table_name,
> > ordinal_position
> >
> >
> > AMB
> > "wnfisba" wrote:
> >
> >> I am looking for a specific Datetime column and I don't know what table
> >> it
> >> resides in.
> >>
> >> How can I query the systables looking for all those columns with Datetime
> >> type???
> >>
> >> Thank You!
>
>
>
Author
2 Sep 2005 8:46 PM
Alejandro Mesa
Aaron,

Thanks for the comment.


AMB

Show quote
"Aaron Bertrand [SQL Server MVP]" wrote:

> Just a couple of things,
>
> (a) upper case (e.g. INFORMATION_SCHEMA.COLUMNS) should be used as opposed
> to lower case, so that code will work equally well on case sensitive
> collations.
>
> (b) I would probably use DATA_TYPE IN ('DATETIME', 'SMALLDATETIME') because,
> while not explicitly specified, the OP may not care if the column is
> SMALL(DATETIME), may not know which datetime type it actually is, or may not
> even know the difference.
>
> A
>
>
>
>
> "Alejandro Mesa" <AlejandroM***@discussions.microsoft.com> wrote in message
> news:BEC6B9ED-970C-4C35-AB7B-0D8C14738734@microsoft.com...
> > Use the view information_schema.columns instead.
> >
> > select
> > table_schema,
> > table_name,
> > ordinal_position,
> > column_name,
> > data_type
> > from
> > information_schema.columns
> > where
> > data_type = 'datetime'
> > and objectproperty(object_id(quotename(table_schema) + '.' +
> > quotename(table_name)), 'IsUserTable') = 1
> >  and objectproperty(object_id(quotename(table_schema) + '.' +
> > quotename(table_name)), 'IsMSShipped') = 0
> > order by
> > table_schema,
> > table_name,
> > ordinal_position
> >
> >
> > AMB
> > "wnfisba" wrote:
> >
> >> I am looking for a specific Datetime column and I don't know what table
> >> it
> >> resides in.
> >>
> >> How can I query the systables looking for all those columns with Datetime
> >> type???
> >>
> >> Thank You!
>
>
>
Author
2 Sep 2005 7:24 PM
wnfisba
It did not return any rows???



Show quote
"Alejandro Mesa" wrote:

> Use the view information_schema.columns instead.
>
> select
>     table_schema,
>     table_name,
>     ordinal_position,
>     column_name,
>     data_type
> from
>     information_schema.columns
> where
>     data_type = 'datetime'
>     and objectproperty(object_id(quotename(table_schema) + '.' +
> quotename(table_name)), 'IsUserTable') = 1
>      and objectproperty(object_id(quotename(table_schema) + '.' +
> quotename(table_name)), 'IsMSShipped') = 0
> order by
>     table_schema,
>     table_name,
>     ordinal_position
>
>
> AMB
> "wnfisba" wrote:
>
> > I am looking for a specific Datetime column and I don't know what table it
> > resides in.
> >
> > How can I query the systables looking for all those columns with Datetime
> > type???
> >
> > Thank You!
Author
2 Sep 2005 7:30 PM
Alejandro Mesa
Can you post the statement you are suing?


AMB

Show quote
"wnfisba" wrote:

> It did not return any rows???
>
>
>
> "Alejandro Mesa" wrote:
>
> > Use the view information_schema.columns instead.
> >
> > select
> >     table_schema,
> >     table_name,
> >     ordinal_position,
> >     column_name,
> >     data_type
> > from
> >     information_schema.columns
> > where
> >     data_type = 'datetime'
> >     and objectproperty(object_id(quotename(table_schema) + '.' +
> > quotename(table_name)), 'IsUserTable') = 1
> >      and objectproperty(object_id(quotename(table_schema) + '.' +
> > quotename(table_name)), 'IsMSShipped') = 0
> > order by
> >     table_schema,
> >     table_name,
> >     ordinal_position
> >
> >
> > AMB
> > "wnfisba" wrote:
> >
> > > I am looking for a specific Datetime column and I don't know what table it
> > > resides in.
> > >
> > > How can I query the systables looking for all those columns with Datetime
> > > type???
> > >
> > > Thank You!

AddThis Social Bookmark Button