20260821230656

This commit is contained in:
oneao committed 2026-08-21 23:06:56 +08:00
1 parent 2e5d532f23
commit c43b4c8364
144 files changed
+7665 -242

No files matched your search

+30
View File
@@ -0,0 +1,30 @@
import java.io.FileInputStream;
import java.sql.*;
import java.util.Properties;
public class LogPkShow {
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"))) {
for (String t : new String[]{"s_log_login", "s_log_technical", "s_log_audit", "s_log_audit_field"}) {
System.out.println("== " + t + " ==");
// PK columns
try (Statement st = conn.createStatement(); ResultSet rs = st.executeQuery(
"SELECT kc.name AS pk, c.name AS col FROM sys.key_constraints kc " +
"JOIN sys.index_columns ic ON ic.object_id = kc.parent_object_id AND ic.index_id = kc.unique_index_id " +
"JOIN sys.columns c ON c.object_id = ic.object_id AND c.column_id = ic.column_id " +
"WHERE kc.type = 'PK' AND kc.parent_object_id = OBJECT_ID('" + t + "') ORDER BY ic.key_ordinal")) {
if (rs.next()) System.out.printf(" PK: %s -> column: %s%n", rs.getString("pk"), rs.getString("col"));
else System.out.println(" PK: NONE !!");
}
// all columns
try (Statement st = conn.createStatement(); ResultSet rs = st.executeQuery(
"SELECT c.name, c.is_identity FROM sys.columns c WHERE c.object_id=OBJECT_ID('" + t + "') ORDER BY c.column_id")) {
StringBuilder sb = new StringBuilder(" cols: ");
while (rs.next()) sb.append(rs.getString(1)).append(rs.getBoolean("is_identity") ? "(identity) " : " ");
System.out.println(sb);
}
}
}
}
}