Download as pdf or txt
Download as pdf or txt
You are on page 1of 19

December 10th, 2018

1
Table of Contents

Introduction .................................................................................................................................................. 3
Purpose/Prerequisites .................................................................................................................................. 3
Setting the context........................................................................................................................................ 3
Example ..................................................................................................................................................... 4
Selecting the Database ......................................................................................................................... 4
Adding the context to the Query .......................................................................................................... 4
Query Tips ..................................................................................................................................................... 6
The Queries ................................................................................................................................................... 7
1. What application does this Part Family belong to? ......................................................................... 7
2. What application does this Part Family, or partial information of the Part Family, belong to?...... 8
3. What Part Families contain a given property, property description, or property category? ........ 10
4. What Property Formulas contain this text?................................................................................... 11
5. What Subpart Formulas contain this text? .................................................................................... 12
6. What Connection Formulas contain this text? .............................................................................. 13
7. What Connections use this Part Family? ....................................................................................... 14
8. What Properties are outputting to this Components Database table? ......................................... 15
9. What Database Specs refers to this Components Database table? .............................................. 16
10. What Part Families contain these subparts, descriptions, etc.? .................................................... 17
11. What Part Families contain these Connections? ........................................................................... 18
12. What Part Families contain these specifications? ......................................................................... 19

2
Introduction

Rulestream utilizes tables within SQL databases to store and retrieve information, such as the rules of an
application as well as the data provided during a session of running a Rulestream application. The
session information is stored in a “Projects” database while the rules that define an application are
stored in a “Rules” database.

The data of a “Rules” database is maintained and viewed via the Rulestream Architect application,
however it was designed for the specific task of creating applications. There are times when it is
necessary to look across all of the data within a “Rules” database to find information, relationships, etc.
The queries documented here provide an example of how to look across the data contained within a
“Rules” database to find such information.

Purpose/Prerequisites

 The following information is provided to illustrate the utility of using queries against a
Rulestream Rules database. The queries provided should be thought of as examples. Modify
them as necessary to achieve the desired results.
 The screenshots were made using a system running SQL Server 2014 Management Studio. The
information provided will apply to any version of SQL Server supported by Rulestream, however
the interfaces depicted may be slightly different if not using SQL Server 2014 Management
Studio.
 The user of this document should be able to login to SQL Server on their system and have a basic
understanding of databases, tables and how to execute a query.

Setting the context

Depending on the nature of a SQL query (I.e., What the query is looking for) it may be necessary to
specify the Database(s) against which it is to be run. We’ll refer to this as the “context”.

Here are two ways to set the context for a Query that needs it:

1. Select the database from the Object Explorer first, THEN select the New Query option to open
and execute the query. Confirmation that you are in the correct context is available in the
lower-right window of the Query window

2. Add the following lines to the start of your main query:

3
USE _____________  provide the name of the database exactly as it appears in the Object Explorer
GO

Example
Selecting the Database

1. Login to SQL Server 2014


2. Expand the Databases folder
3. Select the database against which the query will be run (or select the database from the
dropdown list of databases available as indicated by (5) at the upper-left of the screenshot)
4. Select the menu option to create a [New Query]
5. Confirm that the context is as expected
6. Cut-and-Paste the query
7. Modify as necessary
8. [! Execute] the query
9. View results

Adding the context to the Query

4
1. Login to SQL Server 2014
2. Expand the Databases folder
3. Enter the following code before the query to be used:

USE _________  In this example (see screenshot) we’re using the RS_Box_08163_Rules database
GO

4. Cut-and-Paste the query


5. Modify as necessary
6. [! Execute] the query
7. View results
8. Confirm that the correct context was used

5
Query Tips

When specifying a portion of a string, use the “%” as a wildcard. For instance, to search for any text that
contains the letters “ord”, provide the query: %ord%.

Here are some more examples:

Query string Example words in a Database Words found


%ord% Reword, Order, Ordinary, Word, For, Reword, Order, Ordinary, Word
ord% Tree Order, Ordinary
%ord Reword, Word
ord <null>
%% Reword, Order, Ordinary, Word, For, Tree

Instructions for how to alter a query are contained within the query as comments. These lines are
prefixed with, “- -“, the indicator that the line is a comment rather than an actionable part of the query.
Follow the instructions for modifying the text and then remove the “- -“.

Cut-and-Paste the contents of the “Query:” box into a query window within SQL Server, make whatever
changes are necessary to perform the search needed (see Examples), set/confirm the context and then
[! Execute] the query.

6
The Queries
In all of the following examples, instructions for using the queries are contained within the queries
themselves. Using the comment delimiter of “- -“, we have attempted to highlight these instructions by
setting the font to black italic. When you paste these queries into the query window of SQL
Management Studio this formatting will be lost

1. What application does this Part Family belong to?

Input: Part Family System Name


Output: Application containing the Part Family
Context: A Rules database

Query:
SELECT Part_Family_ID,
Part_Family.Name AS Part_Family_System_Name,
Part_Family.PrettyName AS Part_Family_Display_Name,
Application.Name AS Application_System_Name,
Application.PrettyName AS Application_Display_Name
FROM Part_Family
INNER JOIN Application ON
Application.App_ID = Part_Family.App_ID
WHERE

-- Replace the XXX's with the ...


Part_Family.Name = 'XXX' –- ...Part Family system name

Example:

Part_Family.Name = ‘Box’

7
2. What application does this Part Family, or partial information of the Part Family,
belong to?

Input: Part Family System Name (or partial), Description, Knowledge Source, etc. (see comments
within the query for examples/ideas)
Output: Application containing the Part Family
Context: A Rules database

Query:
-- Find a part family by partial name or description or comments and provide details
SELECT Part_Family.Name AS Part_Family_System_Name,
Application.Name AS Application_System_Name,
Part_Family_ID,
Part_Family.Top_Level,
Part_Family_Category.Name AS Category,
Knowledge_Source.Name AS Knowledge_Source,
Part_Family.Description,
Part_Family.Output_Table_Name,
Part_Family.Last_Update_Date,
Part_Family.Last_Update_UserID,
Part_Family.Comments AS Rule_Author_Comments
FROM Part_Family
INNER JOIN Application ON
Application.App_ID = Part_Family.App_ID
LEFT JOIN Part_Family_Category ON
Part_Family_Category.Category_ID = Part_Family.Category_ID
LEFT OUTER JOIN Knowledge_Source ON
Knowledge_Source.ID = Part_Family.Knowledge_Source_ID
WHERE
-- Pick ONE of the lines below or combine with "AND" or "OR" for multiple conditions.
-- Leave the rest commented out.
-- For Example:
-- Part_Family_Name LIKE ‘%CONVEY%’
-- AND Top_Level = 1

-- Replace the XXX's between the %'s with any portion of the ...
-- Part_Family.Name LIKE '%XXX%' -- ... Part Family system name
-- Part_Family.Description LIKE '%XXX%' -- ... Part Family description
-- Part_Family.Comments LIKE '%XXX%' -- ... Part Family comments added by architect
-- Part_Family_Category.Name LIKE '%XXX%' -- ... Category name
-- Part_Family_Knowledge_Source.Name LIKE '%XXX%' -- ... Knowledge Source name

-- Part_Family.Top_Level = 1 -- Use for top-level parts only


-- Part_Family.Top_Level = 0 -- Use for all but top-level parts
-- Part_Family.Output_Table_Name LIKE '%%' -- Find Part Families that write to a component DB table
-- Part_Family.Output_Table_Name IS NOT NULL -- Find all output table Part Families
ORDER BY
Part_Family.Name ASC,
Application.Name ASC

Example:

Part_Family.Name LIKE ‘Bo%’

8
Example Setup:

Here are some examples of setting-up the “Where” clause to search on various things. Examples of data
you need to provide are underlined. See the query for more information.

WHERE
Part_Family.Name LIKE '%Bo%'

WHERE
Part_Family.Description LIKE '%defines a box%'

WHERE
Part_Family.Output_Table_Name LIKE '%MaterialData%'

9
3. What Part Families contain a given property, property description, or property
category?

Input: Property, Property Description, Spec Category, etc.


Output: Application and Part Family containing the input information
Context: A Rules database

Query:
--- Find all part families that contain properties by name, category, or description.
SELECT Application.Name AS Application,
Part_Family.Name AS Part_Family,
Property_Spec.Name AS Prop_System_Name,
Property_Spec.PrettyName AS Prop_Display_Name,
Value_Datatype.Name AS Data_Type,
Spec_Category.Name AS Property_Category,
Property_Spec.Description
FROM Property_Spec
INNER JOIN Value_Datatype ON
Value_Datatype.Value_Datatype_ID = Property_Spec.Value_Datatype_ID
INNER JOIN Part_Family ON
Part_Family.Part_Family_ID = Property_Spec.Owner_Part_Family_ID
INNER JOIN Application ON
Application.App_ID = Part_Family.App_ID
LEFT JOIN Spec_Category ON
Spec_Category.Category_ID = Property_Spec.Category_ID
WHERE
-- Pick ONE of the lines below or combine with "AND" or "OR" for multiple conditions.
-- Leave the rest commented out.

-- Replace the XXX's between the %'s with any portion of the ...
-- Property_Spec.Name LIKE '%XXX%' -- ... Property name
-- Spec_Category.Name LIKE '%XXX%' -- ... Property Category name
-- Property_Spec.Description LIKE '%XXX%'-- ... Property description

ORDER BY
Property_Spec.Name ASC,
Application.NAME ASC

Example:

Spec_Category.Name LIKE '%design'

10
4. What Property Formulas contain this text?

Input: Search text


Output: The containing formula and its Part Family information
Context: A Rules database

Query:
-- Find all properties with formulas that contain certain text
SELECT Application.Name AS Application,
Part_Family.Name AS Part_Family,
Property_Spec.Name AS Prop_System_Name,
Property_Spec.PrettyName AS Prop_Display_Name,
Value_Datatype.Name AS Data_Type,
Property_Constraint_Relation.Context,
Property_Spec.Description,
Formula_Type.Description As Formula_Type,
Property_Formula.Formula
FROM Property_Formula
LEFT JOIN Property_Constraint ON
Property_Constraint.Prop_Con_ID = Property_Formula.Prop_Con_ID
LEFT JOIN Property_Constraint_Relation ON
Property_Constraint_Relation.Prop_Con_ID = Property_Constraint.Prop_Con_ID
LEFT JOIN Property_Spec ON
Property_Spec.Prop_Spec_ID = Property_Constraint_Relation.Prop_Spec_ID
LEFT JOIN Part_Family ON
Part_Family.Part_Family_ID = Property_Spec.Owner_Part_Family_ID
INNER JOIN Value_Datatype ON
Value_Datatype.Value_Datatype_ID = Property_Spec.Value_Datatype_ID
INNER JOIN Application ON
Application.App_ID = Part_Family.App_ID
LEFT JOIN Formula_Type ON
Formula_Type.Formula_Type = Property_Formula.Formula_Type
WHERE
Formula_Type.Entity_Type_ID = 'PROP'
AND

-- Replace the XXX's between the %'s with ...


Property_Formula.Formula LIKE '%XXX%' -- ... the search string

ORDER BY
Application.NAME ASC,
Part_Family.Name ASC,
Property_Spec.Name ASC,
Formula_type.Description

Example:

Property_Formula.Formula LIKE '%Me.%'

11
5. What Subpart Formulas contain this text?

Input: Search text


Output: Subpart and Formula
Context: A Rules database

Query:
-- Find all subparts with formulas that contain certain text
SELECT Application.Name AS Application,
Part_Family.Name AS Part_Family,
Subpart_Link_Spec.Name AS Subpart_System_Name,
Subpart_Link_Spec.PrettyName AS Subpart_Display_Name,
Subpart_Constraint_Relation.Context,
Subpart_Link_Spec.Description,
Formula_Type.Description As Formula_Type,
Subpart_Formula.Formula
FROM Subpart_Formula
LEFT JOIN Subpart_Constraint ON
Subpart_Constraint.Subpart_Con_ID = Subpart_Formula.Subpart_Con_ID
LEFT JOIN Subpart_Constraint_Relation ON
Subpart_Constraint_Relation.Sub_Con_ID = Subpart_Constraint.Subpart_Con_ID
LEFT JOIN Subpart_Link_Spec ON
Subpart_Link_Spec.Subpart_Link_Spec_ID = Subpart_Constraint_Relation.Sub_Spec_ID
LEFT JOIN Part_Family ON
Part_Family.Part_Family_ID = Subpart_Link_Spec.Owner_Part_Family_ID

INNER JOIN Application ON


Application.App_ID = Part_Family.App_ID
LEFT JOIN Formula_Type ON
Formula_Type.Formula_Type = Subpart_Formula.Formula_Type
WHERE
Formula_Type.Entity_Type_ID = 'SUB'
AND

-- Replace the XXX's between the %'s with ...


Subpart_Formula.Formula LIKE '%XXX%' -- ... the search text

ORDER BY
Application.NAME ASC,
Part_Family.Name ASC,
Subpart_Link_Spec.Name ASC,
Formula_type.Description

Example:

Subpart_Formula.Formula LIKE '%Me.%'

12
6. What Connection Formulas contain this text?

Input: Search text


Output: Part Family and Connection information
Context: A Rules database

Query:
-- Find all connections with formulas that contain certain text
SELECT Application.Name AS Application,
Part_Family.Name AS Part_Family,
Connection_Spec.Name AS Connection_System_Name,
Connection_Spec.PrettyName AS Connection_Display_Name,
Connection_Constraint_Relation.Context,
Connection_Spec.Description,
Formula_Type.Description As Formula_Type,
Connection_Formula.Formula
FROM Connection_Formula
LEFT JOIN Connection_Constraint ON
Connection_Constraint.Con_Con_ID = Connection_Formula.Con_Con_ID
LEFT JOIN Connection_Constraint_Relation ON
Connection_Constraint_Relation.Con_Con_ID = Connection_Constraint.Con_Con_ID
LEFT JOIN Connection_Spec ON
Connection_Spec.Con_Spec_ID = Connection_Constraint_Relation.Con_Spec_ID
LEFT JOIN Part_Family ON
Part_Family.Part_Family_ID = Connection_Spec.Owner_Part_Family_ID

INNER JOIN Application ON


Application.App_ID = Part_Family.App_ID
LEFT JOIN Formula_Type ON
Formula_Type.Formula_Type = Connection_Formula.Formula_Type
WHERE
Formula_Type.Entity_Type_ID = 'CON'
AND

-- Replace the XXX's between the %'s with ...


Connection_Formula.Formula LIKE '%XXX%' -- ... the search text

ORDER BY
Application.NAME ASC,
Part_Family.Name ASC,
Connection_Spec.Name ASC,
Formula_type.Description

Example:

Connection_Formula.Formula LIKE '%Re%'

13
7. What Connections use this Part Family?

Input: Part Family


Output: Connection(s)
Context: A Rules database

Query:
-- Find all connections that have a specific valid part family
SELECT Application.Name AS Application,
Owner_Part_Family.Name AS Owner_Part_Family,
Connection_Spec.Name AS Connection_System_Name,
Connection_Spec.PrettyName AS Connection_Display_Name,
Connection_Spec.Description,
Valid_Part_Family.Name As Valid_Part_Family
FROM Connection_Valid_Part_Families
LEFT JOIN Connection_Spec ON
Connection_Spec.Con_Spec_ID = Connection_Valid_Part_Families.Con_Spec_ID
LEFT JOIN Part_Family Valid_Part_Family ON
Valid_Part_Family.Part_Family_ID = Connection_Valid_Part_Families.Valid_Part_Family_ID
LEFT JOIN Part_Family Owner_Part_Family ON
Owner_Part_Family.Part_Family_ID = Connection_Spec.Owner_Part_Family_ID
INNER JOIN Application ON
Application.App_ID = Owner_Part_Family.App_ID
WHERE

-- Replace the XXX's between the %'s with any portion of the ...
Valid_Part_Family.Name LIKE '%XXX%' -- ... Part Family name

ORDER BY
Application.NAME ASC,
Owner_Part_Family.Name ASC,
Connection_Spec.Name ASC,
Valid_Part_Family.Name ASC

Example:

Valid_Part_Family.Name LIKE '%BOM%'

14
8. What Properties are outputting to this Components Database table?

Input: Components DB Table


Output: Properties writing to this Table
Context: A Rules database

Query:
-- Find all properties that output to component database table
SELECT Application.Name AS Application,
Part_Family.Name AS Part_Family,
Property_Spec.Name AS Prop_System_Name,
Property_Spec.PrettyName AS Prop_Display_Name,
Part_Family.Output_Table_Name As Output_Table,
Property_Spec.Output_Table_Column_Name As Output_Column
FROM Property_Spec
INNER JOIN Value_Datatype ON
Value_Datatype.Value_Datatype_ID = Property_Spec.Value_Datatype_ID
INNER JOIN Part_Family ON
Part_Family.Part_Family_ID = Property_Spec.Owner_Part_Family_ID
INNER JOIN Application ON
Application.App_ID = Part_Family.App_ID
LEFT JOIN Spec_Category ON
Spec_Category.Category_ID = Property_Spec.Category_ID
WHERE

-- Pick ONE of the lines below or combine with "AND" or "OR" for multiple conditions.
-- Leave the rest commented out.

-- Replace the XXX's between the %'s with any portion of the ...
-- Property_Spec.Output_Table_Column_Name LIKE '%XXX%' -- ... Column name
-- Part_Family.Output_Table_Name LIKE '%XXX%' -- ... Table name

Property_Spec.Output_Table_Column_Name IS NOT NULL -- Get all mapped properties

ORDER BY
-- Use this for ordering by database...
-- Part_Family.Output_Table_Name ASC,
-- Property_Spec.Output_Table_Column_Name ASC

-- Or use this instead for ordering by Application and Part Family...


Application.Name ASC,
Part_Family.Name ASC,
Property_Spec.Name ASC

Example:

15
9. What Database Specs refers to this Components Database table?

Input: Components DB Table


Output: Referring Database Specs
Context: A Rules database

Query:
-- Find all db specs that refer to a specific component database tables
SELECT Application.Name AS Application,
Part_Family.Name AS Part_Family,
DB_Spec.Name AS DB_Spec_System_Name,
DB_Spec.PrettyName AS DB_Spec_Display_Name,
Spec_Category.Name As DB_Spec_Category,
DB_Constraint_Relation.Context,
DB_Constraint.Table_Name
FROM DB_Constraint
INNER JOIN DB_Constraint_Relation ON
DB_Constraint_Relation.DB_Con_ID = DB_Constraint.DB_Con_ID
INNER JOIN DB_Spec ON
DB_Spec.DB_Spec_ID = DB_Constraint_Relation.DB_Spec_ID
INNER JOIN Part_Family ON
Part_Family.Part_Family_ID = DB_Spec.Owner_Part_Family_ID
INNER JOIN Application ON
Application.App_ID = Part_Family.App_ID
LEFT JOIN Spec_Category ON
Spec_Category.Category_ID = DB_Spec.Category_ID
WHERE

-- Replace the XXX's between the %'s with any portion of the ...
-- DB_Constraint.Table_Name LIKE '%XXX%' -- Table/View name

ORDER BY
-- Use this for ordering by database table name ...
-- DB_Constraint.Table_Name ASC,

-- Or use this instead for ordering by Application and Part Family...


Application.Name ASC,
Part_Family.Name ASC,
DB_Spec.Name ASC

Example:

DB_Constraint.Table_Name LIKE '%MO%'

16
10. What Part Families contain these subparts, descriptions, etc.?

Input: Subpart, Subpart Category, Subpart Description, etc.


Output: The containing Part Families
Context: A Rules database

Query:
-- Find all part families that contain subparts by name, etc.
SELECT Application.Name AS Application,
Part_Family.Name AS Part_Family,
Subpart_Link_Spec.Name AS Subpart_System_Name,
Subpart_Link_Spec.PrettyName AS Subpart_Display_Name,
Spec_Category.Name AS Subpart_Category,
Subpart_Link_Spec.SubpartLinkType,
Subpart_Link_Spec.Description
FROM Subpart_Link_Spec
INNER JOIN Part_Family ON
Part_Family.Part_Family_ID = Subpart_Link_Spec.Owner_Part_Family_ID
INNER JOIN Application ON
Application.App_ID = Part_Family.App_ID
LEFT JOIN Spec_Category ON
Spec_Category.Category_ID = Subpart_Link_Spec.Category_ID
WHERE

-- Pick ONE of the lines below or combine with "AND" or "OR" for multiple conditions.
-- Leave the rest commented out.

-- Replace the XXX's between the %'s with any portion of the ...
Subpart_Link_Spec.Name LIKE '%XXX%' -- ... Subpart collection name
-- Spec_Category.Name LIKE '%XXX%' -- ... Subpart collection category name
-- Subpart_Link_Spec.Description LIKE '%XXX%' -- ... Subpart collection description

ORDER BY
Subpart_Link_Spec.Name ASC,
Application.NAME ASC

Example:

Subpart_Link_Spec.Name LIKE '%Bill%

17
11. What Part Families contain these Connections?

Input: Connection Name, Connection Description, etc.


Output: The containing Part Families
Context: A Rules database

Query:
-- Find all part families that contain connections by name
SELECT Application.Name AS Application,
Part_Family.Name AS Part_Family,
Connection_Spec.Name AS Connection_System_Name,
Connection_Spec.PrettyName AS Connection_Display_Name,
Spec_Category.Name AS Connection_Category,
Connection_Spec.ConnectionType,
Connection_Spec.Description
FROM Connection_Spec
INNER JOIN Part_Family ON
Part_Family.Part_Family_ID = Connection_Spec.Owner_Part_Family_ID
INNER JOIN Application ON
Application.App_ID = Part_Family.App_ID
LEFT JOIN Spec_Category ON
Spec_Category.Category_ID = Connection_Spec.Category_ID
WHERE

-- Pick ONE of the lines below or combine with "AND" or "OR" for multiple conditions.
-- Leave the rest commented out.

-- Replace the XXX's between the %'s with any portion of the ...
Connection_Spec.Name LIKE '%XXX%' -- ... Connection name
-- Connection_Category.Name LIKE '%XXX%' -- ... Connection category name
-- Connection_Spec.Description LIKE '%XXX%' -- ... Connection description

ORDER BY
Connection_Spec.Name ASC,
Application.NAME ASC

Example:

Subpart_Link_Spec.Name LIKE '%UI%

18
12. What Part Families contain these specifications?

Input: Spec Name, Spec Type, Spec Description, etc.


Output: The containing Part Families
Context: A Rules database

Query:
-- Find all part families that have a certain type of specification or specification with a certain name
SELECT Application.Name AS Application,
Part_Family.Name AS Part_Family,
Spec.Name AS Spec_System_Name,
Spec.PrettyName AS Spec_Display_Name,
--Spec_Category.Name AS Spec_Category,
Spec_System.Name As Spec_Type
FROM Spec
INNER JOIN Part_Family ON
Part_Family.Part_Family_ID = Spec.Owner_Part_Family_ID
INNER JOIN Application ON
Application.App_ID = Part_Family.App_ID
LEFT JOIN Spec_Category ON
Spec_Category.Category_ID = Spec.Category_ID
LEFT JOIN Spec_System ON
Spec_System.System_ID = Spec.System_ID
WHERE

-- Pick ONE of the lines below or combine with "AND" or "OR" for multiple conditions.
-- Leave the rest commented out.

-- Replace the XXX's between the %'s with any portion of the ...
-- Spec.Name LIKE '%XXX%' -- ... Connection system name
-- Spec_Category.Name LIKE '%XXX%' -- ... Spec category name
Spec_System.Name LIKE '%XXX%' -- ... Spec types

ORDER BY
Spec.Name ASC,
Application.NAME ASC

Example:

Spec_System.Name LIKE '%Word’

19

You might also like