Query by Example facts for kids
Query by Example, or QBE, is a special way to ask questions to a database. It's like filling out a form to find the information you need. QBE helps you search for data in relational databases, which store information in tables. It makes it easier to get data without writing complicated computer code.
Contents
How QBE Started
QBE was created by Moshé M. Zloof at IBM Research in the mid-1970s. At the same time, another database language called SQL was also being developed. QBE was special because it was the first "graphical" query language. This means you could see and interact with tables on a screen.
Instead of typing commands, users would fill in example values in visual tables. This made it much simpler to tell the computer what data you wanted. Many modern database programs still use ideas from QBE today. At first, QBE was only used to find and get data. Later, it was improved to let users add, delete, or change data. You could even create temporary tables with it.
The main idea behind QBE is to make databases easier to use. When you fill out a QBE form, the computer secretly turns your choices into a database language like SQL. Then, this hidden code runs to get your results. This way, you don't have to remember all the tricky details of SQL. It's much faster and simpler for people to pick tables and columns by clicking them.
QBE was a big step in making computer tools for everyday users. It showed how people could develop things without being expert programmers.
Where QBE is Used Today
Today, many database programs use QBE. For example, Microsoft Access has a "Visual Query by Example" feature. Microsoft SQL Server also uses it in its Enterprise Manager. Some newer types of databases, called object-oriented databases, also use QBE.
QBE is based on a logical idea called a "tableau query." It adds some extra features to this idea. It's similar to how SQL is based on something called "relational algebra."
Simple QBE Example
Let's look at an example using a database about suppliers and parts. Imagine you have a table like this:
S | S# | SNAME | OWNER | SCITY |
---|---|---|---|---|
P.SX | J. DOE | ROME |
In this example, you are asking the database to find information.
- `S` stands for Supplier.
- `S#` is the Supplier Number.
- `SNAME` is the Supplier Name.
- `OWNER` is the owner's name.
- `SCITY` is the city where the supplier is located.
When you put `P.SX` under `S#`, you are telling the database to show you the supplier number. The `P.` means "print this." The `SX` is an example value. It helps the database understand what you want. If you put `J. DOE` under `OWNER` and `ROME` under `SCITY`, you are asking for suppliers owned by J. DOE who are located in ROME.
QBE as a General Tool
The idea of QBE is also used more broadly. It's a way for software users to search for things without knowing a special query language. The software automatically creates the search commands for the user. It's like filling in blanks to filter results.
Here are two examples using a "Contacts" table. This table has columns for Name, Address, City, State, and Zipcode.
Example A: Finding Contacts by Name and State
Imagine you have a form like this: Contacts Query Form - Example A: .....Name: Bob ..Address: .....City: ....State: TX ..Zipcode:
You've typed "Bob" in the Name field and "TX" in the State field. The blank fields (Address, City, Zipcode) mean you don't care about those. The software then creates a search command like this:
SELECT * FROM Contacts WHERE Name='Bob' AND State='TX';
This command tells the database to "select all information from the Contacts table where the Name is 'Bob' AND the State is 'TX'."
Example B: Finding Contacts by City and Zipcode
Here's another form: Contacts Query Form - Example B: .....Name: ..Address: .....City: Sampleton ....State: ..Zipcode: 12345
In this case, you're looking for contacts in "Sampleton" city with a "12345" zipcode. The software generates:
SELECT * FROM Contacts WHERE City='Sampleton' AND Zipcode='12345';
Using Wildcards in QBE
More advanced QBE forms let you use "wildcard characters." These are special symbols that stand for "any character" or "any group of characters." For example, an asterisk (`*`) is often used as a wildcard. If you search for "Rob*" in a last name field, it would find names like "Rob," "Robert," "Robertson," or "Roberto."
Contacts Query Form - Example C: .....Name: Rob* ..Address: .....City: ....State: ..Zipcode:
This would create a search command like this:
SELECT * FROM Contacts WHERE Name LIKE 'Rob%'
In standard SQL, the percent sign (`%`) is the wildcard. So, the QBE software changes your asterisk (`*`) into a percent sign (`%`). This makes the form easier for you to use.
It's important for QBE software to be built carefully. This helps prevent something called "SQL injection." This is when tricky users try to enter special code into the forms. If not protected, they could access parts of the database they shouldn't.
See also
In Spanish: Búsqueda mediante ejemplo para niños
- CRUD
- Microsoft Query by Example
- GraphQL
- QBIC