Class 10 DBMS Queries Notes
Class 10 DBMS Queries Notes
---------------------------------------------------------------------------------------------------------------------------------------------------------
CREATE Command
CREATE is a DDL command this will create a table with the specified columns having specified datatypes
Query OK, 0 rows affected This shows that query was successfully executed followed by the time taken to execute it.
-------------------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------------------
INSERTING RECORDS IN DATABASE (DML command)
2. Mention all field names and all values to be inserted in the same order as mentioned fields
INSERT INTO <tablename> (field1, field2, fields3, …) VALUES (value1, value2, value3, …);
3. Mention only specified columns in which you must enter values in the same order
INSERT INTO <tablename> (field1, field3, …) VALUES (value1, value2);
----------------------------------------------------------------------------------------------------------------------------------------------
NOTE: If you explicitly want to insert a NULL value, then it can be done in 2 ways:
----------------------------------------------------------------------------------------------------------------------------------------------
CONSTRAINTS
Used to specify rules for data in a table. There are 6 different constraints in SQL:
UNIQUE, DEFAULT, CHECK, NOT NULL, PRIMARY KEY, FOREIGN KEY
Consider the following example:
Creating a primary table, which is the Parent table and a secondary table which is the Student table with constraints.
NOTE: Parent table (Primary table) is created first and then the Student table (secondary table) to ensure Referential
Integrity, Secondary table references the Primary table.
---------------------------------------------------------------------------------------------------------------------------------------------------------
Activity: Let’s create a table emp with 3 fields: id, department and name
Inserting values:
SELECT keyword
1. Select all rows from emp table (* means all fields from table)
3. AND clause
4. OR clause
5. Select particular columns (condition is optional) One example has been done with WHERE clause and
another has been done without it.
6. DISTINCT clause: gives unique distinct values found in the specified field, eliminates redundancy
7. ALL clause: fetches all values found in the field. Redundancy observed.
IN Clause
NOT IN Clause
13. Searching for NULL (IS NULL, IS NOT NULL)
14. Pattern matching (LIKE clause): % for substring, _ (underscore) for single character
----------------------------------------------------------------------------------------------------------------------------------------------------------
ii) Modify datatype: ALTER TABLE <tablename> MODIFY <fieldname> <new datatype> (new size);
DML command
Specifies the rows to be changed using the WHERE clause
UPDATE <tablename>
SET <column1>=<new value1>, <column2>=<new value2>
WHERE <condition>
DELETE command
DML command
Removes rows from table. If WHERE clause is not specified, will clear all rows (empty table will be left) If
WHERE clause is specified, then specific rows will be created
DELETE FROM <tablename> WHERE <condition>
Let us understand these 2 commands using an example. Recall the ‘emp’ table.
NOTE: In the above query WHERE clause has been mentioned. If WHERE clause is not mentioned in DELETE, then all
rows from the table will be removed
-------------------------------------------------------------------------------------------------------------------------------------------------------
DROP Command
i) DROP TABLE <tablename>; will drop the specified table from the database
ii) DROP TABLE IF EXISTS <tablename>; will drop the specified table from the database only if it exists in
the database
IMPORTANT TERMS: