20260821230656
This commit is contained in:
1 parent
2e5d532f23
commit
c43b4c8364
144 files changed
+7665
-242
No files matched your search
@@ -0,0 +1,36 @@
|
||||
import java.io.FileInputStream;
|
||||
import java.sql.*;
|
||||
import java.util.Properties;
|
||||
|
||||
public class DbState {
|
||||
public static void main(String[] args) throws Exception {
|
||||
Properties props = new Properties();
|
||||
try (FileInputStream in = new FileInputStream(args[0])) { props.load(in); }
|
||||
try (Connection conn = DriverManager.getConnection(props.getProperty("url"), props.getProperty("username"), props.getProperty("password"))) {
|
||||
try (Statement st = conn.createStatement(); ResultSet rs = st.executeQuery("SELECT COUNT(*) FROM sys.foreign_keys")) {
|
||||
rs.next(); System.out.println("physical_fk_count=" + rs.getInt(1));
|
||||
}
|
||||
try (Statement st = conn.createStatement(); ResultSet rs = st.executeQuery("SELECT COUNT(*) FROM sys.tables")) {
|
||||
rs.next(); System.out.println("table_count=" + rs.getInt(1));
|
||||
}
|
||||
// 元数据表 b_id 是否仍是 identity
|
||||
try (Statement st = conn.createStatement();
|
||||
ResultSet rs = st.executeQuery(
|
||||
"SELECT OBJECT_NAME(ic.object_id) AS tbl, ic.name AS col, ic.seed_value, ic.increment_value " +
|
||||
"FROM sys.identity_columns ic " +
|
||||
"WHERE ic.name = 'b_id' ORDER BY tbl")) {
|
||||
System.out.println("identity_b_id_columns (sample):");
|
||||
int n = 0;
|
||||
while (rs.next() && n < 25) { n++; System.out.printf(" %-22s b_id identity(%s,%s)%n", rs.getString("tbl"), rs.getString("seed_value"), rs.getString("increment_value")); }
|
||||
System.out.println(" ... total shown=" + n);
|
||||
}
|
||||
// 最近 30 天内是否新建/修改过表
|
||||
try (Statement st = conn.createStatement();
|
||||
ResultSet rs = st.executeQuery(
|
||||
"SELECT COUNT(*) FROM sys.tables t JOIN sys.objects o ON o.object_id = t.object_id " +
|
||||
"WHERE o.modify_date > DATEADD(day, -30, GETUTCDATE())")) {
|
||||
rs.next(); System.out.println("tables_modified_last_30d=" + rs.getInt(1));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user