Debian Codegraph @

www/schematab.html

raw
1 <!DOCTYPE html>
2 <html><head>
3 <meta name="viewport" content="width=device-width, initial-scale=1.0">
4 <meta http-equiv="content-type" content="text/html; charset=UTF-8">
5 <link href="sqlite.css" rel="stylesheet">
6 <title>The Schema Table</title>
7 <!-- path= -->
8 </head>
9 <body>
10 <div class=nosearch>
11 <a href="index.html">
12 <img class="logo" src="images/sqlite370_banner.gif" alt="SQLite" border="0">
13 </a>
14 <div><!-- IE hack to prevent disappearing logo --></div>
15 <div class="tagline desktoponly">
16 Small. Fast. Reliable.<br>Choose any three.
17 </div>
18 <div class="menu mainmenu">
19 <ul>
20 <li><a href="index.html">Home</a>
21 <li class='mobileonly'><a href="javascript:void(0)" onclick='toggle_div("submenu")'>Menu</a>
22 <li class='wideonly'><a href='about.html'>About</a>
23 <li class='desktoponly'><a href="docs.html">Documentation</a>
24 <li class='desktoponly'><a href="download.html">Download</a>
25 <li class='wideonly'><a href='copyright.html'>License</a>
26 <li class='desktoponly'><a href="support.html">Support</a>
27 <li class='desktoponly'><a href="prosupport.html">Purchase</a>
28 <li class='search' id='search_menubutton'>
29 <a href="javascript:void(0)" onclick='toggle_search()'>Search</a>
30 </ul>
31 </div>
32 <div class="menu submenu" id="submenu">
33 <ul>
34 <li><a href='about.html'>About</a>
35 <li><a href='docs.html'>Documentation</a>
36 <li><a href='download.html'>Download</a>
37 <li><a href='support.html'>Support</a>
38 <li><a href='prosupport.html'>Purchase</a>
39 </ul>
40 </div>
41 <div class="searchmenu" id="searchmenu">
42 <form method="GET" action="search">
43 <select name="s" id="searchtype">
44 <option value="d">Search Documentation</option>
45 <option value="c">Search Changelog</option>
46 </select>
47 <input type="text" name="q" id="searchbox" value="">
48 <input type="submit" value="Go">
49 </form>
50 </div>
51 </div>
52 <script>
53 function toggle_div(nm) {
54 var w = document.getElementById(nm);
55 if( w.style.display=="block" ){
56 w.style.display = "none";
57 }else{
58 w.style.display = "block";
59 }
60 }
61 function toggle_search() {
62 var w = document.getElementById("searchmenu");
63 if( w.style.display=="block" ){
64 w.style.display = "none";
65 } else {
66 w.style.display = "block";
67 setTimeout(function(){
68 document.getElementById("searchbox").focus()
69 }, 30);
70 }
71 }
72 function div_off(nm){document.getElementById(nm).style.display="none";}
73 window.onbeforeunload = function(e){div_off("submenu");}
74 /* Disable the Search feature if we are not operating from CGI, since */
75 /* Search is accomplished using CGI and will not work without it. */
76 if( !location.origin || !location.origin.match || !location.origin.match(/http/) ){
77 document.getElementById("search_menubutton").style.display = "none";
78 }
79 /* Used by the Hide/Show button beside syntax diagrams, to toggle the */
80 function hideorshow(btn,obj){
81 var x = document.getElementById(obj);
82 var b = document.getElementById(btn);
83 if( x.style.display!='none' ){
84 x.style.display = 'none';
85 b.innerHTML='show';
86 }else{
87 x.style.display = '';
88 b.innerHTML='hide';
89 }
90 return false;
91 }
92 var antiRobot = 0;
93 function antiRobotGo(){
94 if( antiRobot!=3 ) return;
95 antiRobot = 7;
96 var j = document.getElementById("mtimelink");
97 if(j && j.hasAttribute("data-href")) j.href=j.getAttribute("data-href");
98 }
99 function antiRobotDefense(){
100 document.body.onmousedown=function(){
101 antiRobot |= 2;
102 antiRobotGo();
103 document.body.onmousedown=null;
104 }
105 document.body.onmousemove=function(){
106 antiRobot |= 2;
107 antiRobotGo();
108 document.body.onmousemove=null;
109 }
110 setTimeout(function(){
111 antiRobot |= 1;
112 antiRobotGo();
113 }, 100)
114 antiRobotGo();
115 }
116 antiRobotDefense();
117 </script>
118 <div class=fancy>
119 <div class=nosearch>
120 <div class="fancy_title">
121 The Schema Table
122 </div>
123 <div class="fancy_toc">
124 <a onclick="toggle_toc()">
125 <span class="fancy_toc_mark" id="toc_mk">&#x25ba;</span>
126 Table Of Contents
127 </a>
128 <div id="toc_sub"><div class="fancy-toc1"><a href="#introduction">1. Introduction</a></div>
129 <div class="fancy-toc1"><a href="#alternative_names">2. Alternative Names</a></div>
130 <div class="fancy-toc1"><a href="#interpretation_of_the_schema_table">3. Interpretation Of The Schema Table</a></div>
131 <div class="fancy-toc1"><a href="#creation_and_modification_of_the_schema_table">4. Creation and Modification Of The Schema Table</a></div>
132 </div>
133 </div>
134 <script>
135 function toggle_toc(){
136 var sub = document.getElementById("toc_sub")
137 var mk = document.getElementById("toc_mk")
138 if( sub.style.display!="block" ){
139 sub.style.display = "block";
140 mk.innerHTML = "&#x25bc;";
141 } else {
142 sub.style.display = "none";
143 mk.innerHTML = "&#x25ba;";
144 }
145 }
146 </script>
147 </div>
148
149
150
151
152
153 <h1 id="introduction"><span>1. </span>Introduction</h1>
154
155 <p>Every SQLite database contains a single "schema table" that stores the
156 schema for that database. The schema for a database is a description of
157 all of the other tables, indexes, triggers, and views that are
158 contained within the database. The schema table looks like this:
159
160 </p><blockquote><pre>
161 CREATE TABLE sqlite_schema(
162 type text,
163 name text,
164 tbl_name text,
165 rootpage integer,
166 sql text
167 );
168 </pre></blockquote>
169
170 <p>The sqlite_schema table contains one row for each table, index, view,
171 and trigger (collectively "objects") in the schema, except there
172 is no entry for the sqlite_schema table itself. See the
173 <a href="fileformat2.html#ffschema">schema storage</a> subsection of the <a href="fileformat2.html">file format</a> documentation for
174 additional information on how SQLite uses the sqlite_schema table
175 internally.
176
177 </p><h1 id="alternative_names"><span>2. </span>Alternative Names</h1>
178
179 <p>The schema table can always be referenced using the name "sqlite_schema",
180 especially if qualifed by the schema name like
181 "main.sqlite_schema" or "temp.sqlite_schema". But for historical
182 compatibility, some alternative names are also recognized, including:
183
184 </p><ol>
185 <li> sqlite_master
186 </li><li> sqlite_temp_schema
187 </li><li> sqlite_temp_master
188 </li></ol>
189
190 <p>
191 Alternatives (2) and (3) only work for the TEMP database associated
192 with each database connection, but alternative (1) works anywhere.
193 For historical reasons, callbacks from the <a href="c3ref/set_authorizer.html">sqlite3_set_authorizer()</a>
194 interface always refer to the schema table using names (1) or (3).
195
196 </p><h1 id="interpretation_of_the_schema_table"><span>3. </span>Interpretation Of The Schema Table</h1>
197
198 <p>The meanings of the fields of the schema table are as follows:
199
200 </p><dl>
201 <dt><b>type</b></dt>
202 <dd>
203 <p>The sqlite_schema.type column will be one
204 of the following text strings: 'table', 'index', 'view', or 'trigger'
205 according to the type of object defined. The 'table' string is used
206 for both ordinary and <a href="vtab.html">virtual tables</a>.</p>
207 </dd>
208
209 <dt><b>name</b></dt><dt>
210 </dt><dd>
211 <p>The sqlite_schema.name column will hold the name of the object.
212 <a href="lang_createtable.html#uniqueconst">UNIQUE</a> and <a href="lang_createtable.html#primkeyconst">PRIMARY KEY</a> constraints on tables cause SQLite to create
213 <a href="fileformat2.html#intschema">internal indexes</a> with names of the form "sqlite_autoindex_TABLE_N"
214 where TABLE is replaced by the name of the table that contains the
215 constraint and N is an integer beginning with 1 and increasing by one
216 with each constraint seen in the table definition.
217 In a <a href="withoutrowid.html">WITHOUT ROWID</a> table, there is no sqlite_schema entry for the
218 PRIMARY KEY, but the "sqlite_autoindex_TABLE_N" name is set aside
219 for the PRIMARY KEY as if the sqlite_schema entry did exist. This
220 will affect the numbering of subsequent UNIQUE constraints.
221 The "sqlite_autoindex_TABLE_N" name is never allocated for an
222 <a href="lang_createtable.html#rowid">INTEGER PRIMARY KEY</a>, either in rowid tables or WITHOUT ROWID tables.
223 </p>
224 </dd>
225
226 <dt><b>tbl_name</b></dt>
227 <dd>
228 <p>The sqlite_schema.tbl_name column holds the name of a table or view
229 that the object is associated with. For a table or view, the
230 tbl_name column is a copy of the name column. For an index, the tbl_name
231 is the name of the table that is indexed. For a trigger, the tbl_name
232 column stores the name of the table or view that causes the trigger
233 to fire.</p>
234 </dd>
235
236 <dt><b>rootpage</b></dt>
237 <dd>
238 <p>The sqlite_schema.rootpage column stores the page number of the root
239 b-tree page for tables and indexes. For rows that define views, triggers,
240 and virtual tables, the rootpage column is 0 or NULL.</p>
241 </dd>
242
243 <dt><b>sql</b></dt>
244 <dd>
245 <p>The sqlite_schema.sql column stores SQL text that describes the
246 object. This SQL text is a <a href="lang_createtable.html">CREATE TABLE</a>, <a href="lang_createvtab.html">CREATE VIRTUAL TABLE</a>,
247 <a href="lang_createindex.html">CREATE INDEX</a>,
248 <a href="lang_createview.html">CREATE VIEW</a>, or <a href="lang_createtrigger.html">CREATE TRIGGER</a> statement that if evaluated against
249 the database file when it is the main database of a <a href="c3ref/sqlite3.html">database connection</a>
250 would recreate the object. The text is usually a copy of the original
251 statement used to create the object but with normalizations applied so
252 that the text conforms to the following rules:
253
254 </p><ul>
255 <li>The CREATE, TABLE, VIEW, TRIGGER, and INDEX keywords at the beginning
256 of the statement are converted to all upper case letters.
257 </li><li>The TEMP or TEMPORARY keyword is removed if it occurs after the
258 initial CREATE keyword.
259 </li><li>Any database name qualifier that occurs prior to the name of the
260 object being created is removed.
261 </li><li>Leading spaces are removed.
262 </li><li>All spaces following the first two keywords are converted into a single
263 space.
264 </li></ul>
265
266 <p>The text in the sqlite_schema.sql column is a copy of the original
267 CREATE statement text that created the object, except normalized as
268 described above and as modified by subsequent <a href="lang_altertable.html">ALTER TABLE</a> statements.
269 The sqlite_schema.sql is NULL for the <a href="fileformat2.html#intschema">internal indexes</a> that are
270 automatically created by <a href="lang_createtable.html#uniqueconst">UNIQUE</a> or <a href="lang_createtable.html#primkeyconst">PRIMARY KEY</a> constraints.</p>
271 </dd>
272 </dl>
273
274 <h1 id="creation_and_modification_of_the_schema_table"><span>4. </span>Creation and Modification Of The Schema Table</h1>
275
276 <p>SQLite creates the schema table upon database creation and modifies
277 its content as SQLite users submit DDL statements for execution. There
278 is no need for users to modify it under normal circumstances, and they
279 bear the risk of <a href="howtocorrupt.html#cfgerr">database corruption</a> if they do modify it.
280 </p>
281