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;






INSERT: The INSERT STATEMENT is used to insert data into a table


Syntax:
INSERT INTO table_name (column1, column2, column3, ...)
VALUES (value1, value2, value3, ...);
OR
INSERT INTO table_name
VALUES (value1, value2, value3, ...);
Example:
INSERT INTO Students (Roll_No,Name,Subject)
VALUES (1,’anil’,’Maths’);


UPDATE: The UPDATE STATEMENT is used to modify existing data in a table.

Syntax:
UPDATE table_name
SET column1 = value1, column2 = value2, ...
WHERE condition;
Example:
UPDATE Students
SET Name= ‘Mahesh’
WHERE Roll_No=1;


DELETE: The DELETE STATEMENT is used to delete records from a table.

Syntax:
DELETE FROM table_name
WHERE condition;
Example:
DELETE FROM Students
WHERE Subject=’Maths’;



SELECT: The SELECT statement is used to select data from a database. The data returned is 

stored in a result table, called the result-set.
Syntax:
SELECT column1, column2, ...
FROM table_name
WHERE condition;
OR
SELECT * 
FROM table_name 
WHERE condition;
Example:
SELECT * 
FROM Students
WHERE Roll_No>=1;







Comments

Popular posts from this blog

sql sort

DBMS Chap 1