Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Primary key
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Defining primary keys in SQL== Primary keys are defined in the [[SQL#Standardization history|ISO SQL Standard]], through the PRIMARY KEY constraint. The syntax to add such a constraint to an existing table is defined in [[SQL:2003]] like this: <syntaxhighlight lang="sql"> ALTER TABLE <table identifier> ADD [ CONSTRAINT <constraint identifier> ] PRIMARY KEY ( <column name> [ {, <column name> }... ] ) </syntaxhighlight> The primary key can also be specified directly during table creation. In the SQL Standard, primary keys may consist of one or multiple columns. Each column participating in the primary key is implicitly defined as NOT NULL. Note that some [[RDBMS]] require explicitly marking primary key columns as <code>NOT NULL</code>.{{citation needed|date=January 2013}} <syntaxhighlight lang="sql"> CREATE TABLE table_name ( ... ) </syntaxhighlight> If the primary key consists only of a single column, the column can be marked as such using the following syntax: <syntaxhighlight lang="sql"> CREATE TABLE table_name ( id_col INT PRIMARY KEY, col2 CHARACTER VARYING(20), ... ) </syntaxhighlight>
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)