Browse DevX
Sign up for e-mail newsletters from DevX

Tip of the Day
Language: SQL Server
Expertise: Beginner
Mar 25, 1997



Building the Right Environment to Support AI, Machine Learning and Deep Learning

Indexes in SQL

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

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 simply perform an equijoin, something like this:

        SELECT Orders.ordernumber, Items.quantity, Items.partno
                FROM Orders, Items
                WHERE Orders.ordernumber = Items.ordernumber;
DevX Pro
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date