Structured Query Language - PDF

Added on - 16 Aug 2021

  • 9

    Pages

  • 1603

    Words

  • 34

    Views

  • 0

    Downloads

Trusted by +2 million users,
1000+ happy students everyday
Showing pages 1 to 3 of 9 pages
Name: Rijna Shrestha
Roll No.: 36
1.Short note on DDL and DML:
Structured Query Language (SQL) is the database language by the use of
which we can perform certain operations on the existing database and also we
can use this language to create a database. SQL uses certain commands like
Create, Drop, Insert etc. to carry out the required tasks.Once data is stored, it
often needs to be modified. Data is inserted, updated and deleted. Commands
that create objects like tables are calledSQL DDL commands. On the other hand,
commands that modify data are calledSQL DML commands.
These SQL commands are mainly categorized into four categories DDL, DML, DCL
&TCL:
DDL:
DDL (Data Definition Language) actually consists of the SQL commands that
can be used to define the database schema. It simply deals with descriptions of
the database schema and is used to create and modify the structure of database
objects in database.
Examples of DDL commands:
oCREATE– is used to create the database or its objects (like table,
index, function, views, store procedure and triggers).
oDROP– is used to delete objects from the database.
oALTER-is used to alter the structure of the database.
oTRUNCATE–is used to remove all records from a table, including all
spaces allocated for the records are removed.
oCOMMENT–is used to add comments to the data dictionary.
oRENAME–is used to rename an object existing in the database.
Query for DDL:
oCreate table: CREATE TABLE Tblscript
(
ID int not null identity(1,1),
Name varchar(50),
Address varchar(50),
Qualification varchar(50),
Age int,
Gender char(50),
)
oAlter table: ALTER TABLE Tblscript
ADD DOB date;
oCreate View: SELECT * FROM Tblscript
DML:
The SQL commands that deals with the manipulation of data present in database
belong to DML or Data Manipulation Language and this includes most of the SQL
statements.
Examples of DML:
SELECT– is used to retrieve data from a database.
INSERT– is used to insert data into a table.
UPDATE– is used to update existing data within a table.
DELETE– is used to delete records from a database table.
Query of DML:
oInsert into table: INSERT INTO Tblscript
values ('Rita','Pokhara','SEE/10','16','Female')
INSERT INTO Tblscript
(Name,Address,Age,Gender)
values ('Sijal','Kathmandu','20','Male')
oUpdate table: select Name from Tblscript
update Tblscript set name='Jerry'
where name='Sijal'
2.Calculated Field:
Acalculated fieldis a field for querying or outputting information that cannot
be directly queried or output from a database table.A computed column is a
virtual column that is not physically stored in the table, unless the column is
marked PERSISTED. A computed column expression can use data from other
columns to calculate a value for the column to which it belongs.The ability to
manipulate field values in query results without altering the data in the
database itself provides many significant benefits.A calculated field either
performs some calculation on database fields to create a value that is not
stored in the database or selects the value from a particular database field
based on customized criteria.
Some examples include:
1.Data can be stored with the appropriate data type
2.Formatting/conversionisgenerallyfasterthroughtheRDBMSin
comparison to the application layer (i.e. PHP, Python)
desklib-logo
You’re reading a preview
Preview Documents

To View Complete Document

Click the button to download
Subscribe to our plans

Download This Document