This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Get Column Value

 
Maja Gralewska
Ranch Hand
Posts: 92
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Does anybody know of a sql statement that will get the default value for a field?? eg: Varchar 20.

I have searched the web and have only been able to find SELECT LEN(colName) FROM tableName
and SELECT DATALENGTH(colName) FROM tableName

but these return the entered value(data actually in the table) eg 6 or in bytes eg 9 Is there any way to get the default value?

Thanks
 
Sagar Rohankar
Ranch Hand
Posts: 2905
1
Java Spring Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maja Gralewska wrote:
Does anybody know of a sql statement that will get the default value for a field?? eg: Varchar 20.


I think this will help, This method will give you information about table, its column, its data type, default value, etc...
 
Maja Gralewska
Ranch Hand
Posts: 92
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, it's very very useful, defiantly going to bookmark it, but the my problem is its getting the values through java methods, but i preferably have to get it using a mySql statement?(almost the whole system is based like that) Any ideas??? Thanks
 
Sagar Rohankar
Ranch Hand
Posts: 2905
1
Java Spring Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maja Gralewska wrote: but i preferably have to get it using a mySql statement?(almost the whole system is based like that) Any ideas??? Thanks

I don't thinks that make any difference, JDBC drivers are vendor specific, so what are you doing using 'DatabaseMetadata' interface, internally it invokes the right procedure/select statement to fetch schema information..

Still you want a MySQL specific query, Have look at this blog entry OR better Googled mysql + get schema information it !!
 
Maja Gralewska
Ranch Hand
Posts: 92
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks,

I have been looking through the web including the official sun mySql page, and this is most probably my fault for not phasing my question perfectly.(sorry) I can get the type eg: VARCHAR 20 and the data eg: MONKEY and the size of monkey eg: 6, but what i am trying to get using a mySql statement is the 20. eg if in the table its set as VARCHAR 55 then i want to get only the 55 not the whole type, just the set size.

Any ideas?
 
Sagar Rohankar
Ranch Hand
Posts: 2905
1
Java Spring Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maja Gralewska wrote:Thanks,

if in the table its set as VARCHAR 55 then i want to get only the 55 not the whole type, just the set size.


The link I posted in my previous reply has the query to get the table information, specifically the query goes like this,



and it return a row, having following column,

Field, Type(varchar(50)), Null(YES/NO), Key, Default, Extra

Hope this help !!

And whats this means
"Potrzeba jest matka wynalazków " (your signature)
 
Maja Gralewska
Ranch Hand
Posts: 92
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes thanks it did, although still need to play around with it so it returns only the value/size of char/varchar.

It means: Necessity is the mother of invention.
 
Sagar Rohankar
Ranch Hand
Posts: 2905
1
Java Spring Ubuntu
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic