Learn SQL : Variations on Insert statement and Interview Questions

SQL : Variations on Insert statement and Interview Questions.

Variations on Insert statement and Interview Questions

Variation on INSERT statement:

There are three variations of insert statement as shown below:
1. Changing the order of the columns:
     You can change the order of the column names as long as the           matching values for each column come in that same order.
Example: We previously use this method:
  INSERT INTO stu_data(student_name, student_rollno, student_mobileno) VALUES ('ABC', 1, 8945372531);
 We also use this method for inserting the data:

  INSERT INTO stu_data(student_rollno, student_mobileno, student_name) VALUES (2, 8945372531, 'ABD');

In this method we change the order and matching values of the columns.

sql Variation on INSERT statement

2. Omitting columns name:

    If you want to enter the data in all values then you have no need      to write the columns name but the      data must be in the same        order as you inserted the column name.
Example:  INSERT INTO stu_data VALUES ('BCD', 3,                                     7654321987);

sql Omitting columns name

3. Leaving some column out : 

    You can also insert few columns like
              INSERT INTO stu_data(student_rollno) VALUES (4);
sql Leaving some column out

   And if you want to insert the remaining data then you can insert by applying 'where' clause with 'INSERT' , which we understood later.


1. What are the subsets of SQL.

The subset of SQL are:
1. Data Definition Language (DDL).

2. Data Manipulation Language (DML).

3. Data Control Language (DCL).

DDL: Allows you to define the structure of the database.

Common DDL commands are: CREATE, DROP, ALTER, 

Common DML commands are: SELECT, INSERT, UPDATE, DELETE.

Common DCL commands are: GRANT, REVOKE.

2.  Explain DDL commands.

CREATE Command: It is used to create the structure of the table inside the database.
SYNTAX: CREATE TABLE table_name(col_1 datatype, col_2 datatype,.......col_N datatype);

DESCRIBE Command: It is used to describe or see the structure of table.
SYNTAX: DESC table_name;

DROP Command: It is used to drop the data with structure of table.
SYNTAX: DROP table_name;

TRUNCATE Command: It is used to delete the records permanently from the database and free the space containing the table.

ALTER Command:  It is used to do changes in the structure of the table.
SYNTAX: ALTER TABLE table_name ADD(col_1 datatype);
                  ALTER TABLE table_name MODIFY(col_1                              datatype);

3. Explain DML Commands.

SELECT Command: It is used to see the records present in the database.
SYNTAX: SELECT * FROM table_name;
                  SELECT col_1,col_2 FROM table_name;
INSERT Command: It is used to insert the record in the database.
SYNTAX: As given above.
UPDATE Command: It is used to change or update the records into the database.
SYNTAX: UPDATE table_name set col_x=value WHERE                              condition;
DELETE Command: It is used to delete or remove the records into the database temporarily.
                  DELETE FROM table_name WHERE expression;

3. Explain DCL Commands.

GRANT Command: It is used to give privileges to database.
REVOKE Command: It is used  to take back privileges from user.
  • We will discuss about all these command later in brief.

For any error related to the data mail to: anshika.chaudhary2510@gmail.com

Previous                                                                                   Next

No comments:

Powered by Blogger.