You are on page 1of 42

INFORMATION SYSTEM

MANAGEMENT LAB
Practical File
BBA-212
Submitted by:
Name:Tushar Gupta
Enrolment No.:14417701720
Course:BBA(G)
Section:4B

1
INDEX
Topic Page No.
1. Steps to start Wamp Server 1
2. Types of SQL commands 5
3. Keys in SQL 10
4. Integrity constraints in SQL 11
5. Press Enter Key as Password 15
6. Create Database 16
7. Open Database 17
8. Create Table Persons 18
9. Create Table Dept 19
10. Create Table Project 20
11. Table Persons Description 21
12. Table Dept Description 22
13. Table Project Description 23
14. Insert data in Persons 24
15. Insert data in Dept 25
16. Insert data in Project 26
17. Primary Key 27
18. Foreign key 28
19. Alter Table Persons 29
20. Alter Table Project 30
21. Rename Table Project 31
22. Show table structure 32
23. Update details for Gender 33
24. Update table using a specific condition 34
25. Delete Statement 35
26. View all records 36
27. Display selective records 37
28. Display selective fields 38
29. Select Distinct 39
30. AND operator 40
31. OR operator 41
32. Order By Clause (Ascending) 42
33. Order By Clause (Descending) 43
34. Like Operator (City name contains 'elh') 44
35. Like Operator (Second letter in name is 'a') 45
36. Like Operator (Last Name starts with "B" or "R") 46
37. Like Operator (Last Name not starts with "B" ,"R" or "P") 47
38. IN operator 48
39. BETWEEN operator 49
40. List of Databases 50
41. List of Tables 51
42. Drop Database 52
43. Delete Table 53
44. SUM Function 54
45. GROUP BY statement 55
46. HAVING Clause 56
47. Create Table Order 57
48. AVG Function 58
49. COUNT Function 59
50. COUN DISTINCT Function 60
51. MAX Function 61
52. MIN Function 62
53. UCASE Function 63
54. LCASE Function 64
55. MID Function 65
56. LEN Function 66
57. CROSS JOIN 67
58. INNER JOIN 68
59. FULL OUTER JOIN 69
60. LEFT OUTER JOIN 70
61. RIGHT OUTER JOIN 71
62. Create table Project1 72
63. Create Table Project2 73
64. UNION 74
65. INTERSECT 75
66. MINUS 76
67. Commit 77
Start Wamp Server

Wamp Server Activated

2
Open MySQL Prompt

Open Root Directory

4
SQL Commands

DDL DML TCL DCL

CREATE INSERT SAVEPOINT GRANT

ALTER UPDATE COMMIT REVOKE

DROP DELETE ROLLBACK

TRUNCATE SELECT

RENAME MERGE

Data Definition Language (DDL)


The data definition statements are used to define, create, modify and delete the
database objects. The database objects are: tables, views, schemas, domains, triggers,
and the procedures that are stored. The changes made by these statements will be
permanent and cannot be got back.

• The SQL keywords that are associated with the DDL statements are: CREATE,
TRUNCATE, RENAME, ALTER and DROP.

• The CREATE command or keyword is used to create a table.

• The ALTER TABLE statement is used to modify or to make alteration in the table or
modification of table’s properties.

• The DROP TABLE statement is used to delete the definition of the table from the
database.

• The TRUNCATE statement is used to delete the data stored in the table.

• The RENAME statement is used to change the name of the table.

6
Data Manipulation Language (DML)
The data manipulation language statements are used to retrieve, add, delete, and
modify the data that is stored in the objects of database. The keywords or statements
that are associated with the data manipulation language are: SELECT INSERT, UPDATE
and DELETE. These are the primary statements of data manipulation language (DML)
and are used widely.

• The INSERT statement is used to insert a new row in the database that is adding
data to a table.

• The SELECT statement is used to retrieve record from one or more tables.

• The UPDATE statement is used to update the data or row in the table.

• The MERGE statement is used to merge two rows or two tables in the database.

• The DELETE statement is used to delete a row from the table in the database.

Transaction Control Language (TCL)

The Transaction Control Language commands are used to track the effects of other commands on the database
and are also used to control the transactional processing in a database.

• The changes made using the transaction control command are permanent and cannot be altered. The
primary keywords or commands of transaction control language are SAVEPOINT, ROLLBACK, and COMMIT.

• The SAVEPOINT command is used to save temporarily.

• The COMMIT command or statement is used to save permanently.

• The ROLLBACK command is used to revoke the changes.

8
Data Control Language (DCL)
The Data Control Language statements are used to allow the user to have a control to
check that who can access the specified objects in the database. The database user
can be a person or the application program.

• With data control language you can restrict or grant the access for the database
objects using GRANT and REVOKE statements of data control language (DCL). These
two statements that are GRANT and REVOKE are the primary statements of the data
control language.

• The data control language also allows you to control the type of access that each of
the users will have to the objects of database. For example, you can specify that
which users can view the specific set of data and which users can manipulate that
specific set of data.

• The GRANT statement is used to grant the permission of right to the user.

• The REVOKE statement is used to tack back the permission of right from the user.

10
Constraint Name & Description Example
The following SQL ensures that the "ID", "LastName", and "FirstName"
NULL Constraint - By default, a
columns will NOT accept NULL values:
column can hold NULL values. The
NOT NULL constraint enforces a
column to NOT accept NULL values. CREATE TABLE Persons (
This enforces a field to always ID int NOT NULL,
contain a value, which means that LastName varchar(255) NOT NULL,
you cannot insert a new record, or FirstName varchar(255) NOT NULL,
update a record without adding a Age int );
value to this field.

The following SQL creates a UNIQUE constraint on the "ID" column when the
UNIQUE Constraint - The UNIQUE
"Persons" table is created:
constraint ensures that all values in
a column are different. Both the
UNIQUE and PRIMARY KEY CREATE TABLE Persons (
constraints prov0069de a guarantee ID int NOT NULL UNIQUE,
for uniqueness for a column or set LastName varchar(255) NOT NULL,
of columns. A PRIMARY KEY FirstName varchar(255),
constraint automatically has a Age int );
UNIQUE constraint. However, you
can have many UNIQUE constraints
per table, but only one PRIMARY
KEY constraint per table.

11

Constraint Name & Description Example


PRIMARY KEY Constraint - The The following SQL creates a PRIMARY KEY on the "ID" column when the
PRIMARY KEY constraint uniquely "Persons" table is created:
identifies each record in a database
table. Primary keys must contain CREATE TABLE Persons (
UNIQUE values, and cannot contain ID int PRIMARY KEY,
NULL values. A table can have only LastName varchar(255) NOT NULL,
one primary key, which may consist FirstName varchar(255),
of single or multiple fields. Age int );
FOREIGN KEY Constraint - A The following SQL creates a relational model assigning FOREIGN KEY on the
FOREIGN KEY is a key used to link "PersonID" column when the "Orders" table is created, linked with already
two tables together. A FOREIGN KEY created PersonID column in Pesrons table:
is a field (or collection of fields) in
one table that refers to the CREATE TABLE Orders (
PRIMARY KEY in another table. The OrderID int NOT NULL PRIMARY KEY,
table containing the foreign key is OrderNumber int NOT NULL,
called the child table, and the table PersonID int FOREIGN KEY REFERENCES Persons(PersonID) );
containing the candidate key is
called the referenced or parent
table.

12
Constraint Name & Description Example
The following SQL creates a CHECK The following SQL creates a CHECK
constraints on AGE numerical column inconstraints on AGE numerical
CUSTOMERS table: CREATE TABLE column and on City text column in
CUSTOMERS( ID int NOT NULL, Persons table: CREATE TABLE
NAME varchar(20) NOT NULL, AGE Persons (
The CHECK constraint is used to int NOT NULL CHECK (AGE >= 18), ID int NOT NULL,
limit the value range that can be ADDRESS char(25), SALARY LastName varchar(255) NOT
placed in a column. If you define a decimal(18, 2), PRIMARY KEY (ID));
NULL,
CHECK constraint on a single FirstName varchar(255),
column it allows only certain values Age int,
City varchar(255),
for this column.
CONSTRAINT CHK_Person CHECK
If you define a CHECK constraint on (Age>=18 AND City='Sandnes') );
a table it can limit the values in The following SQL creates a CHECK constraints on GENDER text column in
certain columns based on values in EMPLOYEE table: CREATE TABLE EMPLOYEE( ID int PRIMARY KEY,
other columns in the row. NAME char(20),
DEPT char(10),
AGE int,
GENDER char(1) CHECK (GENDER in ('M','F')),
SAL int,
Location char(10) );

13

Constraint Name & Description Example


The following SQL creates a DEFAULT constraints on City column in Persons
table to set the default value of column:
The DEFAULT constraint is used to
CREATE TABLE Persons (
insert a default value into a
ID int NOT NULL,
column. The default value will be
LastName varchar(255) NOT NULL,
added to all new records, if no
FirstName varchar(255),
other value is specified.
Age int,
City varchar(255) DEFAULT 'Sandnes' );
The following SQL automatically increment the The following SQL
value in numerical ID column by one value: automatically increment the
AUTOINCREMENT or IDENTITY CREATE TABLE Persons ( value in numerical ID column
Very often we would like the value ID int NOT NULL AUTOINCREMENT, by one value starting from
of the primary key field to be LastName varchar(255) NOT NULL, one:
created automatically every time a
FirstName varchar(255), CREATE TABLE Persons (
new record is inserted. Auto-
increment allows a unique number Age int, ID int IDENTITY(1,1)
to be generated automatically PRIMARY KEY (ID) ); PRIMARY KEY,
when a new record is inserted into LastName varchar(255)
a table. NOT NULL,
FirstName varchar(255),
Age int );

14
Press Enter Key as Password

15

Create Database

16
Open Database

17

Create Table Persons

18
Create Table Dept

19

Create Table Project

20
Table Persons Description

21

Table Dept Description

22
Table Project Description

23

Insert data in Persons

24
Insert data in Dept

25

Insert data in Project

26
Primary Key

27

Foreign key

28
Alter Table Persons

29

Alter Table Project

30
Rename Table Project

31

Show table structure

32
Update details for Gender

33

Update table using a specific condition

34
Delete Statement

35

View all records

36
Display selective records

37

Display selective fields

38
Select Distinct

39

AND operator

40
OR operator

41

Order By Clause (Ascending)

42
Order By Clause (Descending)

43

Like Operator (City name contains ‘elh’)

44
Like Operator (Second letter in name is
‘a’)

45

Like Operator (Last Name starts with “B”


or “R”)

46
Like Operator (Last Name not starts with
“B” ,“R” or “P”)

47

IN operator

48
BETWEEN operator

49

List of Databases

50
List of Tables

51

Drop Database

52
Delete Table

53

SUM Function

54
GROUP BY statement

55

HAVING Clause

56
Create Table Order

57

AVG Function

58
COUNT Function

59

COUN DISTINCT Function

60
MAX Function

61

MIN Function

62
UCASE Function

63

LCASE Function

64
MID Function

65

LEN Function

66
CROSS JOIN

67

INNER JOIN

68
FULL OUTER JOIN

69

LEFT OUTER JOIN

70
RIGHT OUTER JOIN

71

Create table Project1

72
Create Table Project2

73

UNION

74
INTERSECT

75

MINUS

76
Commit

77

You might also like