mssql查询:
成都创新互联制作网站网页找三站合一网站制作公司,专注于网页设计,成都网站制作、成都网站设计,网站设计,企业网站搭建,网站开发,建网站业务,680元做网站,已为上1000+服务,成都创新互联网站建设将一如既往的为我们的客户提供最优质的网站建设、网络营销推广服务!
SELECT so.[id] AS ObjectID,
so.[name] AS ObjectName, so.XType,
(CASE WHEN (LEFT(text, 2) = '/*')
AND (charindex('*/', text) 0) THEN substring([text], 3, patindex('%*/%', text) - 3)
ELSE '' END) AS Comments
FROM syscomments AS sc full join sysobjects AS so ON so.[id] = sc.[id]
WHERE so.[xtype] = 'U' OR so.[xtype] = 'V'
mysql表注释查询:
select table_name,table_comment from information_schema.tables where table_schema = 'image' and table_name ='tableName'
,听说过数据库 可以给字段进行备注,如下语句:
`id` int(10) unsigned NOT NULL auto_increment COMMENT '自增id',
这样之后,我要查看备注,语句是什么呢?如下是我在百度找到的一个语句:
SELECT COLUMN_NAME, DATA_TYPE AS `数据类型`, CHARACTER_MAXIMUM_LENGTH AS `字符长度`, NUMERIC_PRECISION AS `数字长度`, NUMERIC_SCALE AS `小数位数`, IS_NULLABLE AS `是否允许非空`, CASE WHEN EXTRA = 'auto_increment' THEN 1 ELSE 0 END AS `是否自增`, COLUMN_DEFAULT AS `默认值`, COLUMN_COMMENT AS `备注` FROM information_schema.COLUMNS WHERE TABLE_NAME='表名" . $table . "' AND TABLE_SCHEMA = '数据库名" . $database . "'
Java获取数据库的表中各字段的字段名,代码如下:
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.PreparedStatement;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
public class TestDemo {
public static Connection getConnection() {
Connection conn = null;
try {
Class.forName("com.mysql.jdbc.Driver");
String url = "jdbc:mysql://数据库IP地址:3306/数据库名称";
String user = "数据库用户名";
String pass = "数据库用户密码";
conn = DriverManager.getConnection(url, user, pass);
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
return conn;
}
public static void main(String[] args) {
Connection conn = getConnection();
String sql = "select * from AccessType";
PreparedStatement stmt;
try {
stmt = conn.prepareStatement(sql);
ResultSet rs = stmt.executeQuery(sql);
ResultSetMetaData data = rs.getMetaData();
for (int i = 1; i = data.getColumnCount(); i++) {
// 获得所有列的数目及实际列数
int columnCount = data.getColumnCount();
// 获得指定列的列名
String columnName = data.getColumnName(i);
// 获得指定列的列值
int columnType = data.getColumnType(i);
// 获得指定列的数据类型名
String columnTypeName = data.getColumnTypeName(i);
// 所在的Catalog名字
String catalogName = data.getCatalogName(i);
// 对应数据类型的类
String columnClassName = data.getColumnClassName(i);
// 在数据库中类型的最大字符个数
int columnDisplaySize = data.getColumnDisplaySize(i);
// 默认的列的标题
String columnLabel = data.getColumnLabel(i);
// 获得列的模式
String schemaName = data.getSchemaName(i);
// 某列类型的精确度(类型的长度)
int precision = data.getPrecision(i);
// 小数点后的位数
int scale = data.getScale(i);
// 获取某列对应的表名
String tableName = data.getTableName(i);
// 是否自动递增
boolean isAutoInctement = data.isAutoIncrement(i);
// 在数据库中是否为货币型
boolean isCurrency = data.isCurrency(i);
// 是否为空
int isNullable = data.isNullable(i);
// 是否为只读
boolean isReadOnly = data.isReadOnly(i);
// 能否出现在where中
boolean isSearchable = data.isSearchable(i);
System.out.println(columnCount);
System.out.println("获得列" + i + "的字段名称:" + columnName);
System.out.println("获得列" + i + "的类型,返回SqlType中的编号:"+ columnType);
System.out.println("获得列" + i + "的数据类型名:" + columnTypeName);
System.out.println("获得列" + i + "所在的Catalog名字:"+ catalogName);
System.out.println("获得列" + i + "对应数据类型的类:"+ columnClassName);
System.out.println("获得列" + i + "在数据库中类型的最大字符个数:"+ columnDisplaySize);
System.out.println("获得列" + i + "的默认的列的标题:" + columnLabel);
System.out.println("获得列" + i + "的模式:" + schemaName);
System.out.println("获得列" + i + "类型的精确度(类型的长度):" + precision);
System.out.println("获得列" + i + "小数点后的位数:" + scale);
System.out.println("获得列" + i + "对应的表名:" + tableName);
System.out.println("获得列" + i + "是否自动递增:" + isAutoInctement);
System.out.println("获得列" + i + "在数据库中是否为货币型:" + isCurrency);
System.out.println("获得列" + i + "是否为空:" + isNullable);
System.out.println("获得列" + i + "是否为只读:" + isReadOnly);
System.out.println("获得列" + i + "能否出现在where中:"+ isSearchable);
}
} catch (SQLException e) {
e.printStackTrace();
}
}
}