AgerNic.com
WEB DEVELOPER SITE, HTML, CSS, PHP, SQL

SQL PRIMARY KEY


<< Previous Page
SQL tutorial
Next Page >>
SQL tutorial

SQL Tutorial » SQL PRIMARY KEY

What is the primary key in SQL?

A primary key in the SQL table is a field in a table that uniquely identifies each row / record in a database.

Primary keys must contain unique values. A primary key column cannot have NULL values.

Syntax:

CREATE TABLE table_name(
ID_column INT NOT NULL,
NAME_column VARCHAR (20) NOT NULL,
ADDRESS_column CHAR (25),
PRIMARY KEY (ID)
);
Note: You would use these concepts while creating database tables.

To create a PRIMARY KEY constraint on the "ID_column" column when the table_name table already exists, use the following SQL syntax ?

Syntax:

ALTER TABLE table_name
ADD PRIMARY KEY (ID_column);

 

SQL PRIMARY KEY on ALTER TABLE

To create a PRIMARY KEY constraint on the "ID_column" when sql table_name is already created, we use this SQL syntax

ALTER TABLE tabe_name
ADD PRIMARY KEY (ID_column);

To create a PRIMARY KEY constraint onmultiple columns when table_name table already exists, we use the following syntax.

ALTER TABLE table_name
ADD CONSTRAINT PK_table_name PRIMARY KEY (ID_column, NAME_column);

Related subjects:
How to create database phpmyadmin? SQL create table PHP select / view data Conect to MySQLi SQL alter table

Tags: sql primary key: and foreign key, auto increment, clustered, keys multiples, constraint, vs foreign key, vs unique, index, null, identity, What is the primary key in SQL?
What is primary key in SQL with example?
What is primary key and example?
Is a primary key required SQL?

 

DROP (delete) PRIMARY KEY

You can remove(delete) primary key constraints from SQL table with the syntax shown below.:

ALTER TABLE table_name
DROP PRIMARY KEY;

 

SQL primary key auto increment

Auto-increment SQL allows a number to be generated automatically when a new record is inserted into yout table.

The following syntax SQL statement defines the "ID_column" column to be an auto-increment primary key field in the "table_name":

MySQL uses the AUTO_INCREMENT to perform an auto-increment feature.

ALTER TABLE Persons AUTO_INCREMENT=25;

By default AUTO_INCREMENT is starting from value 1



sql primary key: and foreign key, auto increment, clustered, keys multiples, constraint, vs foreign key, vs unique, index, null, identity, What is the primary key in SQL?
What is primary key in SQL with example?
What is primary key and example?
Is a primary key required SQL?
SQL PRIMARY KEY - sql tutorial

Online Editor
ONLINE EDITOR

news templates


COLOR PICKER

news templates
This tool makes it easy to create, adjust, and experiment with custom colors for the web.


HTML Templates
news templates
Magnews2 is a modern and creative free magazine and news website template that will help you kick off your online project in style.


CSS HTML Layout
news templates
Find here examples of creative and unique website layouts.


Free CSS HTML Menu
news templates
Find here examples of creative and unique website CSS HTML menu.


Home - Database
SQL - Database
SQL Syntax
SQL Select Data
SQL Insert Data
SQL Update
SQL Delete Row
PHP mysqli_query()
SQL order
SQL Create Database
SQL Display Data
SQL Count()
SQL mysqli_connect
SQL create table
SQL Where And & Or
SQL like Syntax
SQL Between Operator
SQL IN Operator
Online Editor
ONLINE EDITOR

news templates


COLOR PICKER

news templates
This tool makes it easy to create, adjust, and experiment with custom colors for the web.


HTML Templates
news templates
Magnews2 is a modern and creative free magazine and news website template that will help you kick off your online project in style.


CSS HTML Layout
news templates
Find here examples of creative and unique website layouts.


Free CSS HTML Menu
news templates
Find here examples of creative and unique website CSS HTML menu.


Error: Unable to connect to MySQL. Debugging errno: 1045 Debugging error: Access denied for user 'u142985959_ager'@'localhost' (using password: YES)