SQL tutorial for beginners.

SQL tutorial for beginners:

SQL is a database language that performs operations on a database.

Database commands are as bellow,
DDL: Data Definition Language.
DML: Data Manipulation Languages.
DQL: Data Query Language.

DDL:
Data Definition Language is the command used to create and modify the structure of the database.
It consists of CREATE, ALTER, DROP, TRUNCATE operations.

1 CREATE:
It is used to create a database Table.

Syntax:

   CREATE TABLE TABLE_NAME(ELEMENTS....);
		 
   CREATE TABLE STUDENT(NAME VARCHAR(20),AGE INTEGER(4));

NOTE: Student is name of table.

2 ALTER:
It is used to modify the content of the Table, such as Add column, Modify and Rename.

a) ADD-

It is used Add new coloumn to Table.

Syntax:

   ALTER TABLE TABLE_NAME ADD(COLUMN_NAME DATA_TYPE...);
		 		
   ALTER TABLE STUDENT ADD(COLLAGE_NAME VARCHAR(25));

b). MODIFY:-
It is used to change the datatype column of an existing table.

Syntax:

    ALTER TABLE TABLE_NAME MODIFY COLOUMN_NAME DATA_TAPE;
		 		
	ALTER TABLE STUDENT MODIFY COLLAGE_NAME VARCHAR(40);

size of varchar is changed from 25 to 40.

C). RENAME:-
It is used to rename column and table names in the database.

Syntax:

    ALTER TABLE TABLE_NAME RENAME OLD_NAME TO NEW_NAME;
		 		
		 	
		1. FOR COLOUMN:
		 		     ALTER TABLE STUDENT RENAME NAME TO USER_NAME;
		 		      		
		 2. FOR TABLE:
		  		     ALTER TABLE STUDENT RENAME TO PUBLIC;

changed the table name from student to public.

d). DROP:-
It is used to drop entire column from table.

    ALTER TABLE Table_Name DROP COLUMN CLOUMN_NAME;
				
	ALTER TABLE STUDENT DROP COLUMN AGE;

3.DROP:
It is command used to delete entire table from database.

    DROP TABLE TABLE_NAME;
		     
	DROP TABLE PUBLIC;

4.TRUNCATE:
It is used to delete the entire data from a table, without affecting the structure of the data.

Syntax: TRUNCATE TABLE TABLE_NAME;

    TRUNCATE TABLE TABLE_NAME;
    TRUNCATE TABLE STUDENT;

DML:
Data Manipulation Language is responsiable to INSERT,UPDATE,DELETE.

  1. INSERT:
    This is used to insert values to elements in table.

    INSERT INTO TABLE_NAME VALUES(ELEMENT DATA_TYPE...);
	   	     
	INSERT INTO STUDENT VALUES('ALIEN','Mars','18');

2.UPDATE:
This is user to update particular datwa from table.

Syntax:

    INSERT TABLE_NAME SET COLUMN=VALUE... WHERE CONDITION;

    INSERT STUDENT SET NAME='MIKE' WHERE AGE='18';

3.DELETE:
This is used to delete particular row of the table.

Syntax:

   DELETE FROM TABLE_NAME WHERE CONDITION;
   DELETE FROM STUDENT WHERE AGE='18';

DQL:
Data Query Language is used to retrive the data from table.

Syntax:

   SELECT COLUMN_NAME FROM TABLE_NAME;

   SELECT NAME, AGE FROM STUDENT;
   SELECT * FROM STUDENT;

*:- IS USED TO PRINT ENTIRE TABLE.

Data structure interview questions

SQL Interview questions

TCS NQT-2021 coding questions

Snake game using python

c interview questions

Leave a Comment