-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex-sql.html
More file actions
50 lines (40 loc) · 1.99 KB
/
index-sql.html
File metadata and controls
50 lines (40 loc) · 1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<!-- SECCIÓN INDEX -->
<div id="index-section">
<div id="adsense-container" style="width: 350px; position: absolute; left: 0px;"></div>
<div class="inner-modal">
<div class="inner" style="padding: 0px;">
<h1>SQL CREATE INDEX Statement</h1>
<p>The CREATE INDEX statement is used to create indexes in tables. Indexes help retrieve data from the
database faster.
Users cannot see the indexes—they are only used to speed up searches and queries.</p>
<p><strong>Note:</strong> Updating a table with indexes takes more time than updating a table without,
because indexes also need updating. Only create indexes on columns that will be frequently searched
against.</p>
<h2>CREATE INDEX Syntax</h2>
<pre><code class="language-sql">-- Creates a regular index (duplicate values allowed)
CREATE INDEX index_name
ON table_name (column1, column2, ...);
-- Creates a unique index (duplicate values not allowed)
CREATE UNIQUE INDEX index_name
ON table_name (column1, column2, ...);</code></pre>
<h2>CREATE INDEX Example</h2>
<p>Create an index named "idx_lastname" on the "last_name" column in the "patients" table:</p>
<pre><code class="language-sql">CREATE INDEX idx_last_name
ON patients (last_name);</code></pre>
<p>Create an index on multiple columns (last_name + first_name):</p>
<pre><code class="language-sql">CREATE INDEX idx_pname
ON patients (last_name, first_name);</code></pre>
<h2>DROP INDEX Statement</h2>
<p>Use DROP INDEX to delete an index. Syntax varies by database:</p>
<pre><code class="language-sql">-- MS Access
DROP INDEX index_name ON table_name;
-- SQL Server
DROP INDEX table_name.index_name;
-- DB2 / Oracle
DROP INDEX index_name;
-- MySQL
ALTER TABLE table_name
DROP INDEX index_name;</code></pre>
</div>
</div>
</div>