Skip to content

Commit 5bfcb76

Browse files
committed
add syntax, examples
1 parent 26b91c5 commit 5bfcb76

1 file changed

Lines changed: 70 additions & 2 deletions

File tree

README.md

Lines changed: 70 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Compare Difference In T-SQL Queries at Runtime
44
![CI Status](https://travis-ci.org/llouislu/tsql-diff.svg?branch=master) ![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)
55

66
## Install
7-
1. Go to [release](https://github.com/llouislu/tsql-diff/releases) and download the latest version.
7+
1. Go to [release](https://github.com/llouislu/tsql-diff/releases) and download the latest **Release** version.
88
2. execute install.sql in your target database.
99

1010
## Uninstall
@@ -19,19 +19,87 @@ Please refer to the doc/examples while reading this section.
1919
There is a `Diff` schema in your target database after you successfully installed this library.
2020

2121
### Compare two queries in strings
22+
#### Syntax
23+
```sql
24+
Diff.CompareString
25+
@EXP_QueryString NVARCHAR(max),
26+
-- expected query string
27+
@ACT_QueryString NVARCHAR(max),
28+
-- actual query string
29+
@ExplicitColumnOrder TINYINT = 1,
30+
-- optional, set default value 1 to compare column order
31+
@ExplicitColumnName TINYINT = 1,
32+
-- optional, set default value 1 to compare column name(s)
33+
@CompareData TINYINT = 1
34+
-- optionalset default valueet 1 to reorder data rows and compare the difference
35+
```
36+
#### Output
37+
- An `INT`, a sum of error values
38+
- Detailed difference in log
39+
#### Example
2240
```sql
2341
DECLARE @status_code INT;
2442
EXEC @status_code = Diff.CompareString 'Select 1', 'Select 2';
2543
```
2644

2745
### Compare two queries in files
46+
#### Syntax
47+
```sql
48+
Diff.Compare
49+
@ExpectedFilePath NVARCHAR(max),
50+
-- file path of expected query
51+
@ActualFilePath NVARCHAR(max),
52+
-- file path of actual query
53+
@ExplicitColumnOrder TINYINT = 1,
54+
-- optional, set default value 1 to compare column order
55+
@ExplicitColumnName TINYINT = 1,
56+
-- optional, set default value 1 to compare column name(s)
57+
@CompareData TINYINT = 1
58+
-- optionalset default valueet 1 to reorder data rows and compare the difference
59+
```
60+
#### Output
61+
- An `INT`, a sum of error values
62+
- Detailed difference in log
63+
#### Example
2864
```sql
2965
DECLARE @status_code INT;
3066
EXEC @status_code = Diff.Compare 'path/to/query1.sql', 'path/to/query2.sql';
3167
```
3268

3369
### Compare pairs of queries in a folder
70+
#### Syntax
71+
```sql
72+
Diff.CompareFolder
73+
@FolderPath NVARCHAR(1024) = N'/root/data/t',
74+
-- location of a folder where T-SQL files are stored
75+
-- accepts both blackslashes on Windows and forwardslashes on *nix
76+
@ModifierName NVARCHAR(32) = N'Model',
77+
-- a filename suffix in identifying the current file as an anchor/master/standard/expected query
78+
-- e.g. In the filename 'q01Model.sql', 'Model' indicates the file is marked as correct.
79+
@FileSuffix NVARCHAR(8) = N'.sql'
80+
-- a filename extension of T-SQL files
81+
```
82+
#### Output
83+
- Detailed difference in log
84+
#### Example
3485
```sql
3586
declare @status_code INT;
36-
exec Diff.ComapreFolder @FolderPath='/root/data/t', @ModifierName='Model'
87+
exec Diff.ComapreFolder @FolderPath='/test', @ModifierName='Model'
3788
```
89+
90+
### Error Values
91+
| value | error |
92+
|:-----:|--------------------------------------------|
93+
| 1 | runtime error or no valid select statement |
94+
| 2 | expected column datatype(s) not matched |
95+
| 4 | column order not matched |
96+
| 8 | column names not matched |
97+
| 16 | data row not matched |
98+
99+
### Limitations
100+
101+
- T-SQL Diff only receives the first `SELECT` statement as input to compare.
102+
103+
- `WITH` statements (e.g. cte) in `SELECT` are not supported
104+
105+
- Custom datatypes defined by CLR are not supported

0 commit comments

Comments
 (0)