可以在表中找到行数:
select count(*) from tablename
是否可以找到表中的列数?
SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS WHERE table_catalog = 'database_name' -- the database AND table_name = 'table_name'
SELECT COUNT(COLUMN_NAME) FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_CATALOG = 'Database name' AND TABLE_SCHEMA = 'dbo' AND TABLE_NAME = 'table name'
在Java中使用JDBC:
String quer="SELECT * FROM sample2"; Statement st=con.createStatement(); ResultSet rs=st.executeQuery(quer); ResultSetMetaData rsmd = rs.getMetaData(); int NumOfCol=0; NumOfCol=rsmd.getColumnCount(); System.out.println("Query Executed!! No of Colm="+NumOfCol);
SELECT count(*) FROM information_schema.columns WHERE table_name = 'Your_table_nale';
注意:Your_table_nale用您的表名替换