首页 > 编程知识 正文

数据库通配符的使用,mysql选择一个数据库

时间:2023-05-04 19:10:08 阅读:62198 作者:4185

isthereanywaytoselectcolumnswithwildcards。

like

toselectcolumnswithnameshavingtypecouldbe ' select % type % from table _ name '?

not really.you can use the * columnwildcardtoselectallcolumns.if you ' rejoiningmultipletables,youcanselectalllcolumnsfromspecorecpectables

FROM articles AS a

JOIN blurbs AS b ON a.id=b.article

However,you shouldn ' tuse * unless you ' rewritingadbadministration program。

Alternatively,youcanbuildastatementwithinsqloranotherlanguagebyfetchingtablemetadatatogetthecolumnnames.usingjustmysql, youcanquerythecolumnstableintheinformation _ schemadatabasetogetthecolumnnamesandusegroup _ concattobuildthecolumnlistforthe

“选择”、

goup _ concat (column _ name separator ',')、

' FROM ',dbdb,'.',表,

' WHERE. '

FROM INFORMATION_SCHEMA.COLUMNS

where table _ schema=: dbandtable _ name=: table

Replace ':db ',' : table ' and ' . ' withtheappropriatevalues.youcaneventurnitintoapreparedstatemementsoyoucanucanuseite

if you ' renotlimitedtosqlforprogramming, itshouldbelessmessy.thedbdriverforyourlanguageofchoicelikelyoffersmethodstogetmetadata.theactualimplementationwouldbesimililata columnnames,assemble statement,prepare,execute ),but shouldn't be so ugly,asyou'dbeusinganalliang

iwouldbeveryinterestedinseeingthesituationthatthisisactuallyrequired .

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。