Professional Documents
Culture Documents
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
2
Open MySQL Prompt
4
SQL Commands
TRUNCATE SELECT
RENAME MERGE
• The SQL keywords that are associated with the DDL statements are: CREATE,
TRUNCATE, RENAME, ALTER and DROP.
• 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.
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.
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.
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
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
14
Press Enter Key as Password
15
Create Database
16
Open Database
17
18
Create Table Dept
19
20
Table Persons Description
21
22
Table Project Description
23
24
Insert data in Dept
25
26
Primary Key
27
Foreign key
28
Alter Table Persons
29
30
Rename Table Project
31
32
Update details for Gender
33
34
Delete Statement
35
36
Display selective records
37
38
Select Distinct
39
AND operator
40
OR operator
41
42
Order By Clause (Descending)
43
44
Like Operator (Second letter in name is
‘a’)
45
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
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
70
RIGHT OUTER JOIN
71
72
Create Table Project2
73
UNION
74
INTERSECT
75
MINUS
76
Commit
77