Class 10 IT Chapter - Database Topic - DDL in SQL - Arvindzeclass - NCERT Solutions

Post Top Ad

Friday, June 18, 2021

Class 10 IT Chapter - Database Topic - DDL in SQL

What is DDL (Data Definition Language) in SQL?

DDL commands are subset of SQL commands. These commands are primarily used for defining and modifying the structure of a database or a table. These are the following commands used in DDL:

Data Definition Language in SQL

--------------------------------------------------

 Other Topics of this Chapter


-------------------------------------------------


How to use Create command in SQL?

All data in Relational Database is stored in tables, and each table in database is created using Create Table command.

Syntax: Create Table <table name>

              (<column name> <data type> <size>,
                <column name> <data type> <size>,  - - - );

 

Example: Create a table lab which has the following columns:

DDL in SQL
Table - Lab

SQL> Create table Lab
           ( Item_Code       Char(3),
              Item_Name      Varchar(10),
               Price               Float(4,2),
                Quantity          Int,
                 Date_of_Purchase   Date);

 

How to use Alter command in SQL?

Sometimes it may happen that after the table has been created and the values have been entered in a table. we may require to change the definition of the table, so Alter command is used. It is a DDL statement.

 

Table can be altered in one of the three ways:

 

1) By adding a column to an existing table,

2) By changing a column’s definition (data type),

3) By dropping a column of the table.

 

1) Adding column in an existing table

 

Syntax: Alter table <table name>

   Add <column name> <data type> [constraint definition];

 

 Example: SQL> Alter Table Lab

                           Add Item_Company Varchar(10);

 

2) Changing a column’s definition

 

Syntax: Alter Table <table name>

              Modify <column name> <data type>;

 

Example: SQL> Alter Table Lab

                           Modify Item_Name varchar(15);

 

 3) Dropping a column from the table

 

Syntax: Alter Table <table name>

             Drop Column <column name>;

 

Example: SQL> Alter Table Lab

                          Drop Column Item_Company;

How to use Rename command in SQL?

Rename command is used in three ways in SQL:

1) To change Column name in a Table

Syntax: Alter Table <table name>

             Rename column <Column old_Name> to <New_Name>;

 

Example: SQL> Alter Table Lab

                          Rename column Date_of_Purchase to DOP;


2) To change table name in a Database

Syntax: Alter Table <table name>

             Rename to New_Table_Name>;

 

Example: SQL> Alter Table Lab

                          Rename to Shop;

3) To change Database name

Syntax: Alter Database

             <Existing_Database_Name> modify Name = <New_Database_Name>;

 

Example: SQL> Alter Database

                          School modify name = college;

How to use Drop command in SQL

Dropping a table not only deletes the data contained in the table but it also removes the definition of its structure. It is a DDL statement.

 

Syntax:  Drop Table <table name>;

 

Example: SQL> Drop table Employee;

What is Constraints in SQL?

Constraints are used to prevent invalid data entry into the table. They provide methods so to follow the rules of an organization.

 

Constraints in SQL

--------------------------------------------------
 Chapters of Class 10 IT (402) 

Part - A

 
Part - B 

 

1)  Not Null is neither a zero nor a blank space because zero is a number value and blank space is a character. Not Null constraint on a column ensures that the column doesn’t remain empty.

 

Example: SQL> Create Table Student
                           ( Name Varchar (25) Not Null,
                             Class char(3) );

 

2)  Unique constraint makes it sure that the data entered in a column does not match with the records.

 

Example: SQL> Create Table Student

                           ( Roll-No   char(3)      Unique,

                             Name        Varchar(15)    Not Null,

                             Class          char(3));

 

--------------------------------------------------

Sample Paper of Class 10

-------------------------------------------------

3)  Primary Key constraint makes it sure that data is unique and cell doesn’t remain empty.

 

Example: SQL> Create Table Student

                           ( Roll-No   char(3)  Primary Key,

                             Name        Varchar(15),          

                             Class          char(3));

 

4)  Check constraint makes sure that data entered in a table is within the certain range of our requirement.

 

Example: SQL> Create Table Employee

                           ( EmpNo  char(3),

                             Ename   Varchar(15),

                             Salary  Float(8,2) Check (salary > 0) );

5)  Foreign Key constraint setup a relationship with Primary Key of another table.

 

Example: SQL> Create Table Student

                           ( Roll-No   char(3),              

                             Name      Varchar(15),          

                             Class        char(2),

                              Stream   Char(5)  References

                              School(Stream));

 

--------------------------------------------------
MCQs of All Chapters Class 10 IT (402) 

Part - A

Chapter 4 - Entrepreneurship
Chapter 5 –Green Skills
 
Part - B 

Chapter 1 – Digital Documentation
Chapter 2– Electronic Spreadsheet
Chapter 3 –  Database Management System
Chapter 4 –Web Application

--------------------------------------------------

What are the 5 arithmetic operators in SQL?

SQL statements are made of reserved word or symbols which are used to perform arithmetic operations. These reserved words are called operators in SQL.

 

 
Operators          Description                    Example

+                         Perform Addition             7 + 2 = 9
-                          Perform Subtraction        7 – 2 = 5
*                          Perform Multiplication   7 * 2 = 14
/                           Perform Division             7 / 2 = 3
%                        
Returns remainder            7 % 2 = 1

                               

What are the comparison operators in SQL?

Comparison operators are used to compare two values and return true (1) or false (0).

Operators          Description                    Example

=                      Less than                      7 = 2 False
<=                     Less than equal to        7 <= 2 False
>=                     Greater than equl to     7 >= 2 True
<>                     Not equal to                 7 <> 2 True



What are the 5 logical operators in SQL?

Logical operators are used to combine the conditions in SQL. These are the five logical operators in SQL:

Operators         Description

AND                     All conditions should be true.
OR                         Any condition true.
NOT                      Reverse the meaning of operator.
BETWEEN            Search the value within the set of values.
ALL                       Compare a value to all values.


--------------------------------------------------

Sample Paper of Class 10 IT 402

-------------------------------------------------




No comments:

Post a Comment

Post Top Ad