SQL CREATE TABLE Statement
The SQL CREATE TABLE statement is used to create a new table in a database. A table is a collection of related data stored in a specific manner that makes it easy to access, manage, and update. In SQL, a table is made up of rows and columns, where each column represents a specific attribute of the data and each row represents a single record.
The syntax of the CREATE TABLE statement is as follows:
1CREATE TABLE table_name ( 2 column1 data_type [NULL | NOT NULL], 3 column2 data_type [NULL | NOT NULL], 4 ... 5 columnN data_type [NULL | NOT NULL] 6);
table_name is the name of the table you want to create,
column1, column2, ..., columnN are the names of the columns in the table, and
data_type is the data type of each column. The
NOT NULL keywords specify whether each column can contain a null value or not.
For example, to create a table named
Orders with columns for
OrderDate, you would use the following statement:
1CREATE TABLE Orders ( 2 OrderID INT NOT NULL, 3 CustomerID INT NOT NULL, 4 OrderDate DATE NOT NULL 5);
Once you have created a table, you can insert data into it using the SQL INSERT statement, retrieve data from it using the SQL SELECT statement, and modify data in it using the SQL UPDATE and DELETE statements. You can also create indexes and constraints on the table to enforce data integrity and improve query performance.
It's important to note that the syntax for the CREATE TABLE statement may vary depending on the specific relational database management system (RDBMS) you are using. For example, in Microsoft SQL Server, the CREATE TABLE statement may include options for specifying the table's filegroup, compression, and other characteristics.