Регистрация Правила Главная форума Поиск |
0
- 19.10.2012 - 18:52
|
Нужно сравнить кол-во записей (хотя бы количество, а можно и сами записи) в каждой из таблиц в БД1 с количеством в каждой таблице из БД2. Т.е. по-сути нужно узнать различия двух БД. Обе БД в MSSQL Server. | |
1
- 19.10.2012 - 20:51
| http://msdn.microsoft.com/en-us/library/ms162843.aspx | |
2
- 19.10.2012 - 21:35
| благодарю | |
3
- 22.10.2012 - 11:05
| Кстати, кому интересно - нашел более удобное решение: http://code.google.com/p/sqltablediff/ | |
4
- 23.10.2012 - 00:46
|
CHECKSUM_AGG должна помочь http://msdn.microsoft.com/en-us/library/ms188920.aspx | |
5
- 23.10.2012 - 08:27
|
сравниваю в Excel) Public Sub extract_dif_proc( _ ByVal con_s As String, ByVal rs_s As String, _ ByVal con_s_prev As String, _ ByVal rs_s_alt As String, _ ByRef i As Integer, ByRef idx As Integer, ByVal print_header As Boolean) Dim con As New adodb.Connection Dim rs As New adodb.Recordset Dim con_prev As New adodb.Connection Dim rs_prev As New adodb.Recordset Dim j As Integer Call con.Open(con_s) Call con_prev.Open(con_s_prev) Call rs.Open(rs_s, con, adOpenForwardOnly, adLockReadOnly, adCmdText) Dim eq As Boolean Dim st As String If print_header Then Cells(1, 1) = "rec stat" For j = 1 To rs.Fields.Count Cells(i, j + 1) = rs.Fields(j - 1).Name If Cells(i, j + 1) = "ID" Then idx = j Next i = i + 1 End If Do While Not rs.EOF Call rs_prev.Open(rs_s_alt + rs.Fields(idx - 1) + "';", con_prev, adOpenForwardOnly, adLockReadOnly, adCmdText) eq = True If rs_prev.EOF Then eq = False st = "added" Else For j = 1 To rs.Fields.Count If IsNull(rs.Fields(j - 1)) And Not IsNull(rs_prev.Fields(j - 1)) Or _ IsNull(rs_prev.Fields(j - 1)) And Not IsNull(rs.Fields(j - 1)) Or _ rs.Fields(j - 1) <> rs_prev.Fields(j - 1) _ Then eq = False st = "modified" Exit For End If Next End If If Not eq Then Cells(i, 1) = st For j = 1 To rs.Fields.Count Cells(i, j + 1) = rs.Fields(j - 1) If st <> "added" Then If IsNull(rs.Fields(j - 1)) And Not IsNull(rs_prev.Fields(j - 1)) Or _ IsNull(rs_prev.Fields(j - 1)) And Not IsNull(rs.Fields(j - 1)) Or _ rs.Fields(j - 1) <> rs_prev.Fields(j - 1) _ Then Cells(i, j + 1).Interior.ColorIndex = 6 End If End If Next i = i + 1 End If rs_prev.Close rs.MoveNext Loop rs.Close Call rs_prev.Open(rs_s, con_prev, adOpenForwardOnly, adLockReadOnly, adCmdText) Do While Not rs_prev.EOF Call rs.Open(rs_s_alt + rs_prev.Fields(idx - 1) + "';", con, adOpenForwardOnly, adLockReadOnly, adCmdText) If rs.EOF Then Cells(i, 1) = "removed" For j = 1 To rs_prev.Fields.Count Cells(i, j + 1) = rs_prev.Fields(j - 1) Cells(i, j + 1).Interior.ColorIndex = 3 Next i = i + 1 End If rs.Close rs_prev.MoveNext Loop con.Close con_prev.Close End Sub Public Sub extract_dif() Cells.Clear Dim s As String s = "SELECT * FROM sigs UNION SELECT * FROM 9xx UNION SELECT * FROM Fx;" Dim s_alt As String s_alt = "SELECT * FROM (SELECT * FROM sigs UNION SELECT * FROM 9xx UNION SELECT * FROM Fx) WHERE ID='" Dim i As Integer i = 1 Dim idx As Integer Call extract_dif_proc( _ "Provider=Microsoft.Ace.OLEDB.12.0;Data Source=" + ActiveWorkbook.path + "\БД.accdb;", _ s, _ "Provider=Microsoft.Ace.OLEDB.12.0;Data Source=" + ActiveWorkbook.path + "\1\БД.accdb;", _ s_alt, _ i, idx, i = 1) End Sub | |
| Интернет-форум Краснодарского края и Краснодара |