0% found this document useful (0 votes)
6 views

Database

The document explains SQL commands, differentiating between DDL (Data Definition Language) and DML (Data Manipulation Language), and provides examples of each. It covers SQL operations like TRUNCATE, DELETE, and DROP, as well as joins, indexes, data types, views, triggers, and normalization. Additionally, it outlines the creation of procedures and user management in MySQL.

Uploaded by

akshararoshan97
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Database

The document explains SQL commands, differentiating between DDL (Data Definition Language) and DML (Data Manipulation Language), and provides examples of each. It covers SQL operations like TRUNCATE, DELETE, and DROP, as well as joins, indexes, data types, views, triggers, and normalization. Additionally, it outlines the creation of procedures and user management in MySQL.

Uploaded by

akshararoshan97
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Database

10/04/24 2:28 PM

What are DDL and DML commands in SQL?


• DDL refers to Data Definition Language. DDL commands are used to define database schema i.e., to create and
modify the database object structure in the database. Examples are CREATE, ALTER, DROP, TRUNCATE, etc.
• DML refers to Data Manipulation Language. DML commands are used to manipulate the data within the
database. Examples are: INSERT, UPDATE, DELETE.

Differentiate between TRUNCATE and DELETE commands in SQL.


TRUNCATE DELETE
It is used to remove all records from a database It is used to delete specified records(one or more) from a
table database table
It is a Data Definition Language(DDL) command It is a Data Manipulation Language(DML) command
Faster than DELETE command Slower compared to TRUNCATE command
Cannot be applied for indexed views as it works Can be applied for indexed views
only on tables

DELETE, DROP and TRUNCATE

DROP and TRUNCATE are DDL command while DELETE is a DML command.
DELETE remove the specific row based on the given condition.
TRUNCATE removes all the record from the table at once.
DROP command removes the table or databases and as well as the structure.

What is the left outer join and the right outer join in SQL?
• Left outer join: It returns an entire set of records from the left table along with the matched records from the right
table.
• Right outer join: It returns an entire set of records from the right table along with the matched records from the
left table.

___________________________________________
CREATE PROCEDURE SelectAllCustomers @City nvarchar(30), @PostalCode nvarchar(10)
AS
SELECT * FROM Customers WHERE City = @City AND PostalCode = @PostalCode
GO;

EXEC SelectAllCustomers @City = 'London', @PostalCode = 'WA1 1DP';

SELECT Orders.OrderID, Customers.CustomerName, Orders.OrderDate


FROM Orders
JOIN Customers
ON Orders.CustomerID=Customers.CustomerID;

SELECT * FROM Customers


GROUP BY Salary
ORDER BY salary DESC LIMIT 1,1;

How to create an index?


There are different types of indexes in MySQL, like a regular INDEX, a PRIMARY KEY, or a FULLTEXT index.
Indexes are created on a column basis. Indexing helps to quickly search for results, either by ordering the data on
disk or by telling the SQL engine which location to find your data in.

Syntax:
ALTER TABLE history ADD INDEX(author(10));

What are numeric data types in MySQL?


There are numeric data types for integer, fixed-point, floating-point, and bit values in MySQL. Except for BIT, the
other numeric data types can be signed or unsigned.

Examples:
○ INT - Standard Integer
○ TINYINT - Very Small Integer
○ SMALLINT - Small Integer
○ MEDIUMINT - Medium-sized Integer
○ BIGINT - Large Integer
○ DECIMAL - Fixed-point number
○ FLOAT - Single-precision floating-point number
○ DOUBLE - Double-precision floating-point number
○ BIT - Bit-field

What are string data types in MySQL?


The string data types in MySQL are:
○ CHAR
○ VARCHAR
○ BINARY
○ VARBINARY
○ TINYBLOB
○ BLOB
○ MEDIUMBLOB
○ LONGBLOB
○ TINYTEXT
○ TEXT
○ MEDIUMTEXT
○ LONGTEXT
○ ENUM
○ SET
○ NULL

What are temporal data types in MySQL?


MySQL provides temporal data types for date and time, as well as a combination of date and time. These are:
○ DATE - A date value in CCYY-MM-DD Format
○ TIME - A Time value in hh : mm :ss format
○ DATETIME - Date and time value in CCYY-MM-DD hh : mm :ss format
○ TIMESTAMP - A timestamp value in CCYY-MM-DD hh : mm :ss format
○ YEAR - A year value in CCYY or YY format

What is BLOB?
BLOB is an acronym for a binary large object. It is a string data type used to hold a variable amount of data.

How do you add users in MySQL?


The CREATE command, along with necessary credentials, can be used to add users.
CREATE USER 'testuser' IDENTIFIED BY 'sample password';

What are views in MySQL?


A view is a set of rows returned when a particular query is executed in MySQL. It is also known as a virtual table,
which does not store any data of its own but displays data stored in other tables.

How to create and execute views?


The CREATE VIEW command is used to create a view in MySQL.

The syntax is:


CREATE VIEW [databasename.] view_name [(column_list)] AS select-statement;

What are MySQL triggers?


A task that is executed automatically in response to a predefined database event is known as a trigger. Each trigger is
associated with a table and is activated by commands like INSERT, DELETE, or UPDATE.

How many triggers are possible in MySQL?


There are 6 different types of triggers in MySQL:
○ Before Insert
○ After Insert
○ Before Update
○ After Update
○ Before Delete
○ After Delete

___________________________________________
Normalizationis a database design technique that arranges tables in a style that reduces redundancy and dependency
of data. It splits larger tables into smaller tables and links them using relationships. This helps in avoiding fields that
would be null. It also makes sure that all fields in the table only belong to one domain of data being described.

You might also like