Chuyển đến nội dung chính

Bài đăng

Đang hiển thị bài đăng từ Tháng 9, 2020

Clustered và NonClustered trong SQL Server

Trong bài viết này, mình cố gắng tổng hợp các kiến thức về Clustered và NonClustered thật đơn giản nhất có thể. Dưới đây là cú pháp tạo Clustered và NonClustered Cú pháp:> -- Create a nonclustered index on a table or view CREATE INDEX i1 ON t1 (col1); -- Create a nonclustered index called IX_ProductVendor_VendorID -- on the Purchasing.ProductVendor table using the BusinessEntityID column. CREATE NONCLUSTERED INDEX IX_ProductVendor_VendorID ON Purchasing.ProductVendor (BusinessEntityID) -- Create a clustered index on a table and use a 3-part name for the table CREATE CLUSTERED INDEX i1 ON d1.s1.t1 (col1); -- Syntax for SQL Server and Azure SQL Database -- Create a nonclustered index with a unique constraint -- on 3 columns and specify the sort order for each column CREATE UNIQUE INDEX i1 ON t1 (col1 DESC, col2 ASC, col3 DESC); Trong SQL Server có 2 loại index chính: Clustered Index Chỉ có 1 Clustered Index trong 1 table. Không đòi hỏi unique. Đây là dạng INDEX mà dữ l