Posts

Showing posts with the label Sql

SQL: ALTER TABLE STATEMENT

This SQL tutorial explains how to use the SQL  ALTER TABLE statement  to add a column, modify a column, drop a column, rename a column or rename a table (with lots of clear, concise examples). We've also added some practice exercises that you can try for yourself. DESCRIPTION The SQL  ALTER TABLE statement  is used to add, modify, or drop/delete columns in a table. The SQL ALTER TABLE statement is also used to rename a table. ADD COLUMN IN TABLE Syntax To add a column in a table, the SQL ALTER TABLE syntax is: ALTER TABLE table_name ADD column_name column-definition; Example Let's look at a SQL ALTER TABLE example that adds a column. For example: ALTER TABLE supplier ADD supplier_name varchar2(50); This SQL ALTER TABLE example will add a column called  supplier_name  to the  supplier  table. ADD MULTIPLE COLUMNS IN TABLE Syntax To add multiple columns to an existing table, the SQL ALTER TABLE syntax is: ALTER TABLE table_name ADD (column_1 c...

SQL CREATE TABLE Statement

The SQL CREATE TABLE Statement The CREATE TABLE statement is used to create a table in a database. Tables are organized into rows and columns; and each table must have a name. SQL CREATE TABLE Syntax CREATE TABLE  table_name ( column_name1 data_type ( size ), column_name2 data_type ( size ), column_name3 data_type ( size ), .... ); The column_name parameters specify the names of the columns of the table. The data_type parameter specifies what type of data the column can hold (e.g. varchar, integer, decimal, date, etc.). The size parameter specifies the maximum length of the column of the table. Example CREATE TABLE Persons ( PersonID int, LastName varchar(255), FirstName varchar(255), Address varchar(255), City varchar(255) );