SQL CREATE ALTER DROP TABLE: Difference between revisions
Jump to navigation
Jump to search
(→ALTER) |
(→CREATE) |
||
(8 intermediate revisions by the same user not shown) | |||
Line 2: | Line 2: | ||
* [[SQL#CADT|SQL]] | * [[SQL#CADT|SQL]] | ||
* [[SQL_Data_Types#Overview|SQL Data Types]] | * [[SQL_Data_Types#Overview|SQL Data Types]] | ||
=Overview= | |||
=<tt>CREATE</tt>= | =<tt>CREATE</tt>= | ||
<syntaxhighlight lang='sql'> | <syntaxhighlight lang='sql'> | ||
CREATE TABLE person | CREATE [TEMPORARY] TABLE person | ||
( id smallint, | ( id smallint, | ||
name varchar(30), | name varchar(30) NOT NULL, | ||
CONSTRAINT pk_person PRIMARY KEY (id) | CONSTRAINT pk_person PRIMARY KEY (id) | ||
); | ); | ||
Line 16: | Line 17: | ||
|- | |- | ||
|} | |} | ||
If the <code>TEMPORARY</code> keyword is used, the created table will be [[SQL#Temporary_Table|temporary]] instead of [[SQL#Permanent_Table|permanent]]. | |||
=<tt>ALTER</tt>= | =<tt>ALTER</tt>= | ||
<syntaxhighlight lang='sql'> | <syntaxhighlight lang='sql'> | ||
ALTER TABLE person [...] | ALTER TABLE person [...] | ||
</syntaxhighlight> | |||
==Add/Remove a Column== | |||
<syntaxhighlight lang='sql'> | |||
ALTER TABLE person ADD COLUMN birthday DATE; | |||
</syntaxhighlight> | </syntaxhighlight> | ||
:{| class="wikitable" style="text-align: left;" | :{| class="wikitable" style="text-align: left;" | ||
|- | |- | ||
| [[PostgreSQL_DDL_Operations# | | [[PostgreSQL_DDL_Operations#Add/Remove_a_Column|PostgreSQL]] || [[MySQL_DDL_Operations#Alter_Table|MySQL]] | ||
|- | |- | ||
|} | |} | ||
Line 36: | Line 43: | ||
|- | |- | ||
|} | |} | ||
=Features= | |||
==<tt>AUTO_INCREMENT</tt>== | |||
{{Internal|SQL_AUTO_INCREMENT#Overview|<tt>AUTO_INCREMENT</tt>}} |
Revision as of 17:54, 23 May 2024
Internal
Overview
CREATE
CREATE [TEMPORARY] TABLE person
( id smallint,
name varchar(30) NOT NULL,
CONSTRAINT pk_person PRIMARY KEY (id)
);
If the TEMPORARY
keyword is used, the created table will be temporary instead of permanent.
ALTER
ALTER TABLE person [...]
Add/Remove a Column
ALTER TABLE person ADD COLUMN birthday DATE;
DROP
DROP TABLE person [...]