Professional Documents
Culture Documents
D.B.M.S Assignment-2
D.B.M.S Assignment-2
System (DBMS)
ASSIGNMENT-2:
1. Binary Datatypes:
There are Three types of binary Datatypes which are given
below:
Data Type Description
The data type of the columns may vary from one database to
another. For example, NUMBER is supported in Oracle
database for integer value whereas INT is supported in MySQL.
Any user can also change the name of the table using this
statement.
Table: Employee
Table: Employee
o Suppose, you want to modify the datatypes of
two columns Emp_ContactNo. and Emp_EmailID of
the above Employee table. For this, you have to
type the following query in the SQL:
ALTER TABLE Employee ADD ( Emp_ContactNo. Int,
Emp_EmailID varchar(80) ;
Table: Employee
You can insert a row in the table by using SQL INSERT INTO command.
There are two ways to insert values in a table.
In the first method there is no need to specify the column name where the data
will be inserted, you need only their values.
1. INSERT INTO table_name
2. VALUES (value1, value2, value3....);
The second method specifies both the column name and values which you want
to insert.
1. INSERT INTO table_name (column1, column2, column3....)
2. VALUES (value1, value2, value3.....);
Let's take an example of table which has five records within it.
You can create a record in CUSTOMERS table by using this syntax also.
SQL UPDATE
The SQL commands (UPDATE and DELETE) are used to modify the data
that is already in the database. The SQL DELETE command uses a WHERE
clause.
SQL UPDATE statement is used to change the data of the records held by
tables. Which rows is to be update, it is decided by a condition. To
specify condition, we use WHERE clause.
1. UPDATE table_name
2. SET column_name = expression
3. WHERE conditions
Let's take an example: here we are going to update an entry in the source
table.
SQL statement:
1. UPDATE students
2. SET User_Name = 'beinghuman'
3. WHERE Student_Id = '3'
Updating Multiple Fields:
If you are going to update multiple fields, you should separate each field
assignment with a comma.
SQL UPDATE statement for multiple fields:
1. UPDATE students
2. SET User_Name = 'beserious', First_Name = 'Johnny'
3. WHERE Student_Id = '3'
If you want to access all rows from all fields of the table, use the
following SQL
SELECT syntax with * asterisk sign:
1. SELECT * FROM table_name;
1. INSERT INTO Student VALUES (201, Akash, Delhi, 18, 89, A2),
2. (202, Bhavesh, Kanpur, 19, 93, A1),
3. (203, Yash, Delhi, 20, 89, A2),
4. (204, Bhavna, Delhi, 19, 78, B1),
5. (05, Yatin, Lucknow, 20, 75, B1),
6. (206, Ishika, Ghaziabad, 19, 51, C1),
7. (207, Vivek, Goa, 20, 62, B2);
The following SQL query displays all the values of each column from the above
Student_records table:
1. SELECT * FROM Student_Records;
2. < (Less Than): This condition is used to retrieve rows where a column's
value is less than a specified value.
5. OR: This condition is used to retrieve rows where at least one of the
conditions is true.
6. NOT: This condition is used to retrieve rows where a condition is not true.
7. IN: This condition is used to check if a value matches any value in a list.
8. NOT IN: This condition is used to check if a value does not match any value
in a list.
Unique Constraint:
Ensures that all values in a column (or a combination of columns)
are unique.
Unlike primary keys, unique constraints allow null values, but if a
column has a unique constraint, only one row can have a null
value in that column.
Check Constraint:
Specifies a condition that each row must satisfy.
Used to enforce domain integrity, ensuring that values in a
column meet certain criteria.
The condition can be based on comparisons, arithmetic
operations, or logical expressions.
Default Constraint:
Specifies a default value for a column.
If no value is provided for the column during insertion, the default
value is used.
PRIMARY KEY –
A table can have only one field as primary key. Below query will
create a table named Student and specifies the field ID as primary
key.
UNIQUE –
Purpose:
Null Values:
Primary Key: Does not allow null values. Every row must have a
value for the primary key column.
Unique Key: Allows null values, but if a column has a unique
constraint, only one row can have a null value in that column.
Number of Constraints:
Primary Key: Each table can have only one primary key constraint.
Unique Key: A table can have multiple unique key constraints,
either on a single column or a combination of columns.
Indexing:
Constraint Naming:
CHECK –
Using the CHECK constraint we can specify a condition for a field,
which should be satisfied at the time of entering values for this
field. For example, the below query creates a table Student and
specifies the condition for the field AGE as (AGE >= 18 ). That is,
the user will not be allowed to enter any record in the table with
AGE < 18. Check constraint in detail
1. NOT NULL –
For example, the below query creates a table Student with the
fields ID and NAME as NOT NULL. That is, we are bound to specify
values for these two fields every time we wish to insert a new
row.
2. DEFAULT –
For example, the below query will create a table named Student
and specify the default value for the field AGE as 18.
CREATE TABLE Student
(
ID int(6) NOT NULL,
NAME varchar(10) NOT NULL,
AGE int DEFAULT 18
);
The GROUP BY clause in SQL is used to group rows that have the
same values into summary rows, typically to apply aggregate
functions such as COUNT, SUM, AVG, MAX, or MIN to each
group. It's commonly used in conjunction with the SELECT
statement to generate summary reports from the database.