0% found this document useful (0 votes)
140 views12 pages

DBMS Mit

The document discusses various SQL statements used for creating and managing databases and tables, manipulating data, and performing aggregations and advanced operations. It provides examples of using statements like CREATE DATABASE, CREATE TABLE, INSERT, SELECT, UPDATE, DELETE, ALTER, RENAME, UNION, INTERSECTION, and MINUS to create databases and tables, add/modify/delete data, sort and restrict results, perform aggregations using functions, and compare data between tables.

Uploaded by

loviagarwal1209
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
140 views12 pages

DBMS Mit

The document discusses various SQL statements used for creating and managing databases and tables, manipulating data, and performing aggregations and advanced operations. It provides examples of using statements like CREATE DATABASE, CREATE TABLE, INSERT, SELECT, UPDATE, DELETE, ALTER, RENAME, UNION, INTERSECTION, and MINUS to create databases and tables, add/modify/delete data, sort and restrict results, perform aggregations using functions, and compare data between tables.

Uploaded by

loviagarwal1209
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 12

PROGRAM-1

Objective: Creating an E-R Diagram using Case Tools.

Relationship : A Relationship describes relation between entities. Relationship is represented


using diamonds or rhombus.

There are four types of relationships :

• One to one
• One to many
• Many to many
• Many to one

One to one Relationship :A one-to-one relationship is mostly used to split an entity in two to
provide information concisely and make it more understandable. The figure below shows an
example of a one-to-one relationship.

Example :

One to many Relationship :A one-to-many relationship refers to the relationship between two
entities X and Y in which an instance of X may be linked to many instances of Y, but an instance
of Y is linked to only one instance of X. The figure below shows an example of a one-to-many
relationship.

Example : Student can enroll for only one course .

KCS551 DBMS Page 7


Many-to-Many cardinality :A many-to-many relationship refers to the relationship
between two entities X and Y in which X may be linked to many instances of Y and vice
versa. The figure below shows an example of a many-to-many relationship. Note that a
many-to-many relationship is split into a pair of one-to-many relationships in a physical
Entity Relationship Diagram.

Example : Employee can assign by many projects and project can have many employees.

Many-to-one relationship:When more than one instance of the entity on the left, and
only one instance of an entity on the right associates with the relationship then it is
known as a many-to- one relationship.

Example :Student enrolls for only one course, but a course can have many students.
PROGRAM-2
Objective: Writing SQL Statements using Oracle/MYSQL

Show Database

Commands: show databases;


The information schema in MYSQL is an information database so that we can get the output using the
show databases commands.

1. Create database
Command- create database file name;
The SQL create command used to create new SQL database.

2. USE file name


Command- use file name;
In this file name statement is used to file in SQL database.

3. Drop database
Command- drop database file name;

The drop statement use to drop existing database.

4. Create table

Command – create table file name (id int(11) primary key, name varchar(100) not null, city
varchar(50));

This statement is used to create a table in database.

5. Show table
Command- show table;

Thais statement returns a list of all tables in existing database.


6. Describe table

Command- describe table file name;

This statement shows the structure of table with data types of columns.

7. Insert Data

Command- insert into table_name


(coulmn1, coulmn2, coulmn3……column) values (value 1, value2, value3…value n);

This command used to insert data in table.

8. Select/show data

Command- select*from table name;

The * operator represent all columns of a table. This query returns all the rows and columns from the
table.

9. Update data

Command- update table_name


Set column1=value1, column2=value2, where condition;

This statement used to modify the existing records in table.


10. Delete data
Command- delete table_name
Where condition;

This statement used to delete the existing record from table.


PROGRAM-3
Objective: Restricting and Sorting data statements using MYSQL.

Ascending

The ASC command is used to sort the data returned in ascending order.

Restricting data

Command- select*from table_name


Order by field_name ASC limit=number;

Sorting data without restrictions

Command- select*from table_name


Order by field_name ASC;
Descending order

The DESC command is used to sort data returned in descending order.

Without restriction

Command- select*from table_name


Order by field_name DESC;

With limit

Command- select*from table_name


Order by field_name desc limit=number;
PROGRAM-4
Objective: Aggregating data using group function.

INITIAL Table

1. Count – this statement returns the number of rows that matches a specified criteria.

Command- select count(*) from table_name


Where condition;

2. SUM- this returns the total some of a numeric column.

Command- select SUM (column_name) from table_name


Where condition;

3. Average- AVG() returns the average value of a numeric column.

Command- select AVG(column_name) from table_name


Where condition;

4. MIN- MIN () return the smallest value.

Command- select MIN (column_name) from table_name


Where condition;

5. MAX- this statement returns the largest value of selected column.

Command- select MAX (column_name) from table_name


Where condition;
PROGRAM-5
Objective: Manipulating Data.

1. Update- The update statement is used to modify the existing records in a table.

Command- update table_name


Set column1_name=value,
Coulmn2_name= value…..,
Where condition;

2. Insert- This statement is used to insert a record into the table.

Command- insert into table_name


(field1, field2,….) values (“field1”, “field2”,….);

3. Delete- The delete statement is used to delete existing records in a table.

Commands- delete from table_name


Where condition;
PROGRAM-6
Objective: Creating and Managing tables.

1. Rename- This statement is used to change a column name.

Command- alter table table_name


Rename column old_name to new_name;

2. Alter- This statement is used to alter the table and adding a new column in the existing table.

Command- alter table table_name add column1;

3. Add- This statement is used to add a column into the existing table.

Command- ADD (<column_name><column_type>……);


PROGRAM-7
Objective: To implement union, intersection and minus operator in MYSQL.

1. Union Operator-:

Syntax- select (column names) from table 1


select (column names) from table2

Table1: Student

Table2: course

Command-
Select marks from student
Where state=’RJ’
UNION
Select marks from course
Where state=’RJ’;

Command-
select marks from student
UNION
Select marks from course;
2. UNION All

Syntax- select (column_name)from table1


Union all
Select (column_name) from table 2;

Command-
Select marks from student
Union all
Select marks from course;

3. Intersection:

Syntax: select (column_name) from table1


(where condition)
In select (column_name) from table 2;

Command-

Select marks from student


Where state=’UP’
In (select marks from course where state=’UP’);

4. Minus:

Syntax: select(column_name)from table 1


Where condition
Not in (select (column_name) from table2
Where condition1;

Command-

Select marks from student


Where state=’RJ’
Not in (select marks from course where state=’RJ’);

You might also like