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

SQL CREATE Table


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

SQL Tutorial » CREATE Table

How do you create a new table in SQL Server?

CREATE TABLE statement is used to create in database server a new table.

1. Syntax:

CREATE TABLE your_table_name (
column_1 datatype,
column_2 datatype,
column_3 datatype,
....
column_N datatype,
);

column_1, column_2 ... column_N parameters specify the names of the columns of the table.

Datatype specifies the type of data of the column and it may vary from one database to another database ( text,varchar, integer, date, etc.). For example, INT is supported in MySQL, NUMBER is supported in Oracle database.

 

SQL CREATE TABLE Example

The next example creates a table named "Users" that contains six columns as: ID, Last_Name, First_Name, Address, City and Email:

Example
CREATE TABLE Users (
ID int(11),
Last_Name varchar(120),
Firs_tName varchar(120),
Address varchar(120),
City varchar(60),
Email varchar(60)
);

The ID column is of type int and will hold an integer with 11 digits.
The Last_Name, First_Name, Address columns are varchar and will hold characters, the maximum length for these fields is 120 characters.
City and Email columns are varchar and will hold characters, the maximum length for these fields is 60 characters.

Related subjects:
SQL DROP DataBase SQL update DataBase PHP select / view data Conect to MySQLi SQL insert into table

 

Tags: SQL CREATE Table: primary key, example, if not exists, foreign key, create table and insert data sql, as, from select, with auto increment id, from another table, with index
Can you create a table in SQL?
How do you create a new table in SQL Server?
What is Create Table command in SQL?
How do you create a table in schema?

 

SQL CREATE Table with primary key

The next example creates a table named "Users" that contains six columns with ID as primary key and NOT NULL(these fields cannot be NULL while creating records in the table), Last_Name, First_Name, Address, City and Email:

Example
CREATE TABLE Users (
ID int NOT NULL,
Last_Name varchar(120) NOT NULL,
Firs_tName varchar(120) NOT NULL,
Address varchar(120) NOT NULL,
City varchar(60),
Email varchar(60) NOT NULL,
PRIMARY KEY (ID)
);

 

Create Table Using Another Table

A copy of an existing table can be created using CREATE TABLE.

The new table gets the same column definitions. All columns or specific columns can be selected.

If you create a new table using an old table, the new table will be filled with the existing values from the old table.

CREATE TABLE thenew-table-name AS
SELECT column_1, column_2,..., column_N
FROM existing-table-name
WHERE ....;

 



SQL CREATE Table: primary key, example, if not exists, foreign key, create table and insert data sql, as, from select, with auto increment id, from another table, with index
Can you create a table in SQL?
How do you create a new table in SQL Server?
What is Create Table command in SQL?
How do you create a table in schema?
SQL CREATE Table - 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.


Create a Sticky Navbar with and without ...
CSS Grid Layout. Examples of grid-gap, l...
CSS animation examples: delay, rotate, s...
CSS font weight bold, thin, values, semi...
CSS background color - opacity, gradient...
CSS flex - display: flex - CSS Flexbox L...
CSS border padding...
HTML text center horizontally and vertic...
HTML text input <input type="text"&g...
HTML link color...
How to Link CSS to HTML, external file n...
HTML link - hyperlink...
jQuery replace...
jQuery replaceClass...
jQuery click ()...
jQuery switchClass()...
jQuery draggable()...
jQuery HTML...
jQuery scroll smooth...
jQuery scroll()...