devxlogo

Indexes in SQL

Indexes in SQL

Question:
Is it possible to set indexes between tables in SQL expression?

Answer:
You can establish indexes on SQL tables, but SQL indexes do not create an implied relationship between tables. If you are familiar with PC databases like dBASE, SQL indexes are completely different ? to indicate a relationship between tables in SQL, you need to use the syntax in the CREATE TABLE command that establishes PRIMARY and FOREIGN keys. If your SQL database does not support referential integrity (PRIMARY and FOREIGN keys), you will not be able to establish a formal relationship between two tables. Even without referential integrity,this does not keep you from treating two tables as if they are related.If you need to retrieve data from two logically related tables, you simplyperform an equijoin, something like this:

        SELECT Orders.ordernumber, Items.quantity, Items.partno                FROM Orders, Items                WHERE Orders.ordernumber = Items.ordernumber;

See also  Professionalism Starts in Your Inbox: Keys to Presenting Your Best Self in Email
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist