Stored differently:#
Clustered indexes store data on disk in the order of the index, so the data storage and index storage of clustered indexes are mixed together; whereas non-clustered indexes store the index and data separately.Uniqueness is different:#
Clustered indexes must be unique because they store data in index order and if two pieces of data have the same index value, they will be indistinguishable; whereas non-clustered indexes may or may not be unique.The query efficiency is different:#
For clustered indexes, the query efficiency is often higher than non-clustered indexes, because clustered indexes store data together, and the query can locate the required data rows faster; while for non-clustered indexes, the query needs to look up the indexes first, and then according to the indexes to find the corresponding data rows, so the query efficiency is relatively low.Inserting data is differently efficient:#
For clustered indexes, since the data is stored in the order of the index, it may be necessary to move the existing data when inserting new data, so the efficiency of inserting data is low; while for non-clustered indexes, only the index needs to be updated when inserting data, so the efficiency is relatively high.It should be noted that a table can only have one clustered index, because the data can only be stored in one order; and there can be multiple non-clustered indexes to meet different query requirements. When designing a database, you need to choose different index types according to specific application scenarios and query requirements.