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

VBS 018 - SQL Language Commands

This document provides an overview of SQL and databases. It defines what a database is as a systematic collection of data used for storage and manipulation. It explains that a Database Management System (DBMS) enables users to access, manipulate, and control access to database data. The document also defines SQL as a language used to communicate with databases to perform tasks like storing, updating, searching, and retrieving data. It lists some common DBMS that use SQL and categorizes SQL commands into groups for defining, manipulating, and querying data.

Uploaded by

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

VBS 018 - SQL Language Commands

This document provides an overview of SQL and databases. It defines what a database is as a systematic collection of data used for storage and manipulation. It explains that a Database Management System (DBMS) enables users to access, manipulate, and control access to database data. The document also defines SQL as a language used to communicate with databases to perform tasks like storing, updating, searching, and retrieving data. It lists some common DBMS that use SQL and categorizes SQL commands into groups for defining, manipulating, and querying data.

Uploaded by

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

MANUAL TITLE

DOCUMENT NO. : VBS 018


SARADHA GUIDE – VB & DBMS LAB REV. NO.: R0 DATE: 02/09/2020
GANGADHARAN
COPY :
COLLEGE
DOCUMENT TITLE PAGE 1 OF 5

SQL LANGUAGE COMMANDS


Edition: 1

GETTING STARTED: ORACLE

Open ORACLE Database 10G Express Edition


Run SQL command Line
Prompt opens
Enter connect
username:scott
password:tiger

GETTING STARTED: SQL Server

Open SQL Server 2008


Connect Database Sever
Select Database
Right click - >Create new Prompt
Open -> Right Click on Tables

1.0. What is Data?

In simple words data can be facts related to any object in consideration.


For example: your name, age, height, weight, a picture , image , file , pdf etc., are considered data.

What is a Database?

Database is a systematic collection of data. Databases support storage and manipulation of data. Databases
make data management easy.
Examples:
An online telephone directory would definitely use database to store data pertaining to people, phone
numbers, other contact details, etc.

Your electricity service provider is obviously using a database to manage billing , client related issues, to
handle fault data, etc.

Let's also consider the facebook. It needs to store, manipulate and present data related to members,
their friends, member activities, messages, advertisements and lot more.

What is a Database Management System (DBMS)?

Database Management System (DBMS) is a collection of programs which enables its users to access database,
/conversion/tmp/activity_task_scratch/729313678.docx

manipulate data, reporting / representation of data. It also helps to control access to the database.

Database representation in DBMS

 A collection of records - that is, rows of records, where each column is a field - becomes a table.

PREPARED/REVISED BY : F. JENOSANDANA BRINA ROUVIER REVIEWED & APPROVED BY: D. SARASWATHI


DESIGNATION : ASSISTANT PROFESSOR – BCA DESIGNATION : ASST.PROF. M.Sc(CS)
DATE : 02/09/2020 DATE : 05/09/2020
MANUAL TITLE
DOCUMENT NO. : VBS 018
SARADHA GUIDE – VB & DBMS LAB REV. NO.: R0 DATE: 02/09/2020
GANGADHARAN
COPY :
COLLEGE
DOCUMENT TITLE PAGE 2 OF 5

SQL LANGUAGE COMMANDS


Edition: 1

 In its most common form, a database is just a collection of one or more tables.
 A simple collection of tables such as this is a certain type of database - a flat or flat-file database.
 There is a second type of database as well - relational database, so called because they are set up to
relate the data in multiple tables together.
 To make a table relational, you choose certain fields to be primary keys and foreign keys.
 The primary key in a table is usually the most important one - the one you might use to sort by, for
instance.
 The foreign key usually represents the primary key in another table, which gives you access to that table
in an organized way.

 For example, we might add a field called student ID to our student grade table. That same field, student
ID, may be the primary key in the school registrar's database table, which lists all students. In our table,
then, the student ID field is a foreign key, allowing us to specify individual records in the registrar's table.
 how do you work with the data in that database?
 One popular way is to use Structured Query Language (SQL), SQL to set up a query, which, when
applied to a database, typically returns a dataset of records that matched your SQL query.

2.0. What is SQL?

SQL stands for structured query language is used to communicate with a database. SQL statements
are used to perform tasks such as store, update, search or retrieve data from a database. Some common
relational database management systems that use SQL are: Oracle, Sybase, Microsoft SQL Server, Access,
Ingres, etc.

What are different types of SQL commands?


SQL commands are a set of instructions that are used to interact with the database. SQL commands are
responsible to create and to do all the manipulation on the database. These are also responsible to give/take out
access rights on a particular database. We can grouped Sql Commands into five major categories depending on
their functionality.
 Data Definition Language (DDL)
 Data Manipulation Language (DML)
 Data Query Language (DQL).
 Transaction Control Language (TCL)
 Data Control Language (DCL)

3.0. SQL - STRUCTURED QUERY LANGUAGE


/conversion/tmp/activity_task_scratch/729313678.docx

1. DDL - DATA DEFINITION LANGUAGE


2. DML - DATA MANIPULATION LANGUAGE
3. DATA QUERY LANGUAGE (DQL)
4. DCL - DATA CONTROL LANGUAGE
4. TCL - TRANSACTION CONTOL LANGUAGE

PREPARED/REVISED BY : F. JENOSANDANA BRINA ROUVIER REVIEWED & APPROVED BY: D. SARASWATHI


DESIGNATION : ASSISTANT PROFESSOR – BCA DESIGNATION : ASST.PROF. M.Sc(CS)
DATE : 02/09/2020 DATE : 05/09/2020
MANUAL TITLE
DOCUMENT NO. : VBS 018
SARADHA GUIDE – VB & DBMS LAB REV. NO.: R0 DATE: 02/09/2020
GANGADHARAN
COPY :
COLLEGE
DOCUMENT TITLE PAGE 3 OF 5

SQL LANGUAGE COMMANDS


Edition: 1

4.0. DDL statements [Data Definition Language].

Statements are used to define the database structure or schema. Some examples:
A. CREATE - to create objects in the database
B. ALTER - alters the structure of the database
C. DROP - delete objects from the database
D.TRUNCATE - remove all records from a table, including all spaces allocated for the records are removed

SYNTAX:

A. create table<table_name> (column definition 1, column definition 2,…);

ex: create table employee (first varchar(15), last varchar(20), age number(3), address varchar(30), city
varchar(20), state varchar(20));

B. alter table <table_name> modify (column definition….);

alter table <table_name> add (column definition….);


ex: Alter table Persons add Dateofbirth date;

C. drop table <table_name>;


ex: drop table myemployees;

D. truncate table< table_name>;


ex: truncate Persons employees

5.0. DML Statements [Data Manipulation Language]

Statements are used for managing data within schema objects. Some examples:

B. INSERT - insert data into a table

C. UPDATE - updates existing data within a table

D. DELETE - deletes all records from a table, the space for the records remain

SYNTAX:
A. insert into <table_name> values( alist of data values);
/conversion/tmp/activity_task_scratch/729313678.docx

ex: insert into employee (first, last, age, address, city, state)
values ('Luke', 'Duke', 45, '2130 Boars Nest', 'Hazard Co', 'Georgia');

B. update <table_name> set <column_name>;


ex: update phone_book set last_name = 'Smith', prefix=555, suffix=9292 where prefix = 979;

PREPARED/REVISED BY : F. JENOSANDANA BRINA ROUVIER REVIEWED & APPROVED BY: D. SARASWATHI


DESIGNATION : ASSISTANT PROFESSOR – BCA DESIGNATION : ASST.PROF. M.Sc(CS)
DATE : 02/09/2020 DATE : 05/09/2020
MANUAL TITLE
DOCUMENT NO. : VBS 018
SARADHA GUIDE – VB & DBMS LAB REV. NO.: R0 DATE: 02/09/2020
GANGADHARAN
COPY :
COLLEGE
DOCUMENT TITLE PAGE 4 OF 5

SQL LANGUAGE COMMANDS


Edition: 1

C. delete from <table_name> where <condition>;


ex: delete from employee where lastname = 'May';

6.0. DATA QUERY LANGUAGE (DQL)

A. SELECT - retrieve/Fetch data from the a database


B.
SYNTAX: select <column_name> from <table_name>;
ex: select * from empinfo;
select first, last, city from empinfo;
select last, city, age from empinfo where age > 30;

7.0. DCL Statements [ Data Control Language]

A. GRANT - gives user's access privileges to database

B. REVOKE - withdraw access privileges given with the GRANT command

SYNTAX:

A. grant privileges on <object_name> to <user_name>;

B. revoke privileges on <object_name> to <user_name>;

8.0. Transaction Control [TCL]

Transaction Control (TCL) statements are used to manage the changes made by DML statements.
It allows statements to be grouped together into logical transactions.

COMMIT - save work done

ROLLBACK - restore database to original since the last COMMIT

SAVEPOINT - to set a savepoint using a user-define name.

SYNTAX:
A. commit;
B. rollback;
/conversion/tmp/activity_task_scratch/729313678.docx

C. Savepoint savepoint-name;

9.0. Types of SQL Keys

PREPARED/REVISED BY : F. JENOSANDANA BRINA ROUVIER REVIEWED & APPROVED BY: D. SARASWATHI


DESIGNATION : ASSISTANT PROFESSOR – BCA DESIGNATION : ASST.PROF. M.Sc(CS)
DATE : 02/09/2020 DATE : 05/09/2020
MANUAL TITLE
DOCUMENT NO. : VBS 018
SARADHA GUIDE – VB & DBMS LAB REV. NO.: R0 DATE: 02/09/2020
GANGADHARAN
COPY :
COLLEGE
DOCUMENT TITLE PAGE 5 OF 5

SQL LANGUAGE COMMANDS


Edition: 1

We have following types of keys in SQL which are used to fetch records from tables and to make relationship
among tables or views.

1. Super Key
Super key is a set of one or more than one keys that can be used to identify a record uniquely in a table.
Example : Primary key, Unique key, Alternate key are subset of Super Keys.

2. Primary Key
Primary key is a set of one or more fields/columns of a table that uniquely identify a record in database
table. It can not accept null, duplicate values. Only one Candidate Key can be Primary Key.

3. Unique Key
Uniquekey is a set of one or more fields/columns of a table that uniquely identify a record in database table.
It is like Primary key but it can accept only one null value and it can not have duplicate values.

4. Foreign Key
Foreign Key is a field in database table that is Primary key in another table. It can accept multiple null,
duplicate values. For more help refer the article

10.0. SQL CHECK Constraint

The CHECK constraint is used to limit the value range that can be placed in a column.
If you define a CHECK constraint on a single column it allows only certain values for this column. If you define a
CHECK constraint on a table it can limit the values in certain columns based on values in other columns in the
row.

Example
CREATE TABLE Persons ( ID int NOT NULL, LastName varchar(255) NOT NULL, FirstName varchar(255),
Age int,City varchar(255), CONSTRAINT CHK_Person CHECK (Age>=18 AND City='Sandnes'));
/conversion/tmp/activity_task_scratch/729313678.docx

PREPARED/REVISED BY : F. JENOSANDANA BRINA ROUVIER REVIEWED & APPROVED BY: D. SARASWATHI


DESIGNATION : ASSISTANT PROFESSOR – BCA DESIGNATION : ASST.PROF. M.Sc(CS)
DATE : 02/09/2020 DATE : 05/09/2020

You might also like