sql concepts
CREATE: Create is used to create the database or its objects like table, view, index etc.
Create Table
The CREATE TABLE statement is used to create a new table in a database.
Syntax:
CREATE TABLE table_name
(
Column1 Datatype(Size) [ NULL | NOT NULL ],
Column2 Datatype(Size) [ NULL | NOT NULL ],
...
);
Example:
CREATE TABLE Students
(
Roll_No int(3) NOT NULL,
Name varchar(20),
Subject varchar(20)
);
ALTER: ALTER TABLE statement is used to add, modify, or drop columns in a table.
Add Column
The ALTER TABLE statement in SQL to add new columns in a table.
Syntax:
ALTER TABLE table_name
ADD Column1 Datatype(Size), Column2 Datatype(Size), … ;
Example:
ALTER TABLE Students
ADD Marks int;
Drop Column
The ALTER TABLE statement in SQL to drop a column in a table.
Syntax:
ALTER TABLE table_name
DROP COLUMN column_name;
Example:
ALTER TABLE Students
DROP COLUMN Subject;
Modify Column
The ALTER TABLE statement in SQL to change the data type/size of a column in a table.
Syntax:
ALTER TABLE table_name
ALTER COLUMN column_name datatype(size);
Example:
ALTER TABLE Students
ALTER COLUMN Roll_No float;
DROP: Drop is used to drop the database or its objects like table, view, index etc.
Drop Table
The DROP TABLE statement is used to drop an existing table in a database.
Syntax:
DROP TABLE table_name;
Example:
DROP TABLE Students;
TRUNCATE: Truncate is used to remove all records from the table.
Syntax:
TRUNCATE TABLE table_name;
Example:
TRUNCATE TABLE Students;
Comments
Post a Comment