DBMS R-2021
DBMS R-2021
NAME :……………………………………..
REG NO :……………………………………..
BRANCH :……………………………………..
SEM/YEAR :……………………………………..
1
BETHLAHEM INSTITUTE OF ENGINEERING
KARUNGAL- 629 157
Kanyakumari District
DEPARTMENT OF…………………………………………………..
2022 - 2023
This is to certify that this is the bonafide record of the work done by Mr./Ms.
2
CONTENTS
VIEWS
3
JOINS
4
CONSTRAINTS
5
NESTED QUERIES
6
PROCEDURES
7
8 TRIGGER
FUNCTION
9
RAILWAY RESERVATION
13 MANAGEMENT
3
DATA DEFINITION LANGUAGE (DDL) COMMANDS
[TABLE CREATION]
Ex.No: 1
Date:
Aim
To create a database and write SQL queries to retrieve information from the database.
DDL COMMANDS
Data definition language is used to create a table, alter the structure of table and drop the table.
CREATE
ALTER
RENAME
DROP
TRUNCATE
CREATE Command
It is used to create a table with attributes specified.
Syntax :
create table tablename(field1 datatype(size), field2 datatype(size),…., fieldn datatype(size));
ALTER Command
This query alters the table with new attribute specified.
Syntax:
alter table tablename add (fieldname datatype(size));
DROP Command
To drop the table along with the schema of the table ie, delete the contents of the table as well the
structure.
Syntax:
drop table tablename;
RENAME Command
To change the name of the table.
Syntax:
rename <old name> to <new name>
TRUNCATE Command
It is used to delete the records (values) in the table but the structure of table remains there.
Syntax:
4
truncate table tablename;
SELECT Command
It is used to display the data.
Syntax :
select * from tablename;
SP_HELP Command
It is used to view the table structure.
Syntax :
sp_help tablename;
INSERT Command
It is used to insert the field values into the table.
Syntax :
insert into tablename values(field1, field2, ….,fieldn);
Table creation
create table customer_details (name varchar(20), age int, address varchar(20), id int, salary char(10));
output
Table Created.
Inserting values
(1 row(s) affected)
(1 row(s) affected)
(1 row(s) affected)
(1 row(s) affected)
(1 row(s) affected)
To View Table
5
output
Alter Table
alter table customer_details add department varchar(10);
output
output
(1 row(s) affected)
Truncate Table
truncate table customer_details;
output
6
Command(s) completed successfully.
Drop Table
drop table customer_details;
output
Result
Thus the DDL commands were used sucessfully.
7
Ex.No: 2
Date:
Aim
To perform insertion, deletion, modifying, altering, updating, and viewing record based on
conditions.
DML COMMANDS
DML commands allow the user to manipulate the data in database.
SELECT
INSERT
DELETE
UPDATE
INSERT Command
It is used to insert the values in the database.
Syntax:
insert into tablename values(field1, field2, …, fieldn);
SELECT Command
It is used to select the objects from the database.
Syntax:
Select * from <tablename>;
DELETE Command
It is used to delete the records from the table.
Syntax:
Delete <tablename> where <column name>=value;
UPDATE Command
Table creation
create table bank_details (name varchar(20), city varchar(20),account_num int,amount money)
output
8
Command(s) completed successfully.
Insert values
output
(1 row(s) affected)
(1 row(s) affected)
(1 row(s) affected)
(1 row(s) affected)
(1 row(s) affected)
Update Command
output
(1 row(s) affected)
9
Select Command
Delete Command
output
(1 row(s) affected)
Like Command
10
select name , city from bank_details order by city;
Aggregate Functions
These functions take a collection of values as input and return a single value.
Output
Result
Thus the DML commands are executed successfully.
11
VIEWS AND DCL COMMANDS
Ex.No: 3
Date:
Aim
To execute and verify the SQL commands for views.
Procedure
Step 1: Start
Step 2: Create the table with its essential attributes
Step 3: Insert attribute values into the table.
Step 4: Create the view from the above created table.
Step 5: Execute different commands and extract information from the view.
Step 6: Stop
Definition
View is a table which is a subset of actual table.
View is an object that gives the user a logical view of data from an underlying table.
You can restrict users can view by allowing them to see only a few attributes from the table.
Uses
Creation of views
Syntax: create view viewname as select columnname1, columnname2
from tablename where columnname = “fieldname”
Update View
Syntax: update viewname set columnname=’field’ where
columnname = “field”
Truncate Command
It is used to delete the records(values) but return the structure.
Syntax : truncate table tablename;
Drop Command
It is used to delete contents as well as the structure.
Syntax : drop table tablename;
12
Table creation
create table student_info(stud_name varchar(10),stud_regno int,sex varchar(10),year char(10),college
varchar(25));
output
Insert values
insert into student_info values('jeni', 10905,'female','first','vins');
insert into student_info values('Joshna', 30904,'female','fourth','st.Xavier');
output
(1 row(s) affected)
(1 row(s) affected)
(1 row(s) affected)
(1 row(s) affected)
(1 row(s) affected)
(1 row(s) affected)
View Creation
create view student1 as select * from student_info where year='first';
output
Command(s) completed successfully.
13
select * from student1;
Update view
update student1 set stud_name='Kanika' where stud_regno=10905;
output
(1 row(s) affected)
output
Command(s) completed successfully.
Drop
drop view student1;
output
Command(s) completed successfully.
Dcl Commands:
---transactions
--roll back
---execute the below querries together
begin tran
select * from students;
delete from students where s_name = 'john';
14
select * from students;
rollback;
select * from students;
--commit
---execute the below querries together
begin tran
select * from students;
delete from students where s_name = 'john';
select * from students;
commit;
select * from students;
rollback;
select * from students;
--saving a transaction
---execute the below querries together
15
--execute twice
--then note down the output
Result
Thus the SQL commands for view and DCL has been verified and executed successfully.
16
JOINS
Ex.No: 4
Date:
Aim
To write and execute the queries for join.
Definition
Join is a query in which data is retrieved from two or more tables. A join matches data from two or
more tables, based on the values of one or more columns in each table.
Types
Inner join
Outer join
Natural join
Inner Join
Inner join returns the matching rows from the tables that are being joined.
Outer Join
- Extended form of the inner join
- Rows in one table having no matching rows in the other table will also appear in the result table
with nulls.
Types:
Left outer
Right outer
Full outer
Left Outer Join: Returns matching rows from the tables being joined and also non-matching rows from
the left table in the result and places null values in the attributes that come from the right table.
Right Outer Join: Returns matching rows from the tables being joined and also non-matching rows from
the right table in the result and places null values in the attributes that come from the left table.
Full Outer Join: It pads tuples from the left relation that did not match with any tuple from the right
relation, as well as tuples from the right relation that did not match with any tuple from the left relation
and adds them to the resultant relation.
17
create table marks_details(name varchar(20),m1 int, m2 int,m3 int);
output
Command(s) completed successfully.
output
(1 row(s) affected)
(1 row(s) affected)
(1 row(s) affected)
(1 row(s) affected)
(1 row(s) affected)
output
Command(s) completed successfully.
output
(1 row(s) affected)
18
(1 row(s) affected)
(1 row(s) affected)
(1 row(s) affected)
(1 row(s) affected)
Select marks_details.name,marks_details.m1,marks_details.m2,marks_details.m3,
student_detail.address from marks_details left outer join student_detail on
marks_details.name=student_detail.name;
output
Select marks_details.name,marks_details.m1,marks_details.m2,marks_details.m3,
student_detail.address ,student_detail.age from marks_details right outer join student_detail on
marks_details.name=student_detail.name;
output
19
Full Outer Join
output
output
Command(s) completed successfully.
20
(1 row(s) affected)
(1 row(s) affected)
(1 row(s) affected)
(1 row(s) affected)
(1 row(s) affected)
output
Command(s) completed successfully.
output
(1 row(s) affected)
(1 row(s) affected)
(1 row(s) affected)
(1 row(s) affected)
(1 row(s) affected)
21
select * from student_list2;
i) Union
It includes all the tuples from both the relation.
ii) Intersection
It includes all the tuples that are same in both the relation.
Result
Thus the queries of join has been verified and executed successfully.
22
CONSTRAINTS
Ex.No: 5
Date:
Aim
To execute and verify the constraints in Data Definition Language Commands.
Definition
Constraints are part of the table definition that limits a restriction on the value entered into its
column.
Types of Constraint
Primary Key
Foreign Key / Reference
Check
Unique
Not Null
Null
Default
Primary Key
- Primary key is used to uniquely identify each row in the table.
- Primary Key value must not be null and must be unique across the column.
Check Constraint
- Check Constraint defines a condition that every row must satisfy.
Unique Constraint
- Unique Key is used to ensure that the information in the column for each record is unique.
Null Constraint
- While creating tables, if a row lacks a data value for a particular column, that value is said to be
null.
- Columns of any data types may contain null values unless the column was defined as not null
when the table was created.
23
- The table with foreign key is related to the primary key table from which the foreign key is
derived.
create table employees(empno int primary key, empname varchar(20),job varchar(20),salary int,dept_no
int);
output
Command(s) completed successfully.
output
(1 row(s) affected)
(1 row(s) affected)
(1 row(s) affected)
(1 row(s) affected)
(1 row(s) affected)
Primary Key
24
output
Reason: We inserted same empno in 2 records. It can’t accept because empno is set as primary Key. The
value of primary Key must be unique.
Null Constraint
We are already created one table. Now if we want to add one attribute in the previous table , the
command is.,
output
Command(s) completed successfully.
The table is displayed and the address fields for previous records are displayed as null.
output
(1 row(s) affected)
25
Check Constraint
output
Command(s) completed successfully.
output
The INSERT statement conflicted with the CHECK constraint "CK__employees__salar__442B18F2".
The conflict occurred in database "master", table "dbo.employees", column 'salary'.
The statement has been terminated.
Reason: We set as, the salary should be greater than 10000 but we entered the salary is 8000, so it can’t
accept.
output
Insert Error: Column name or number of supplied values does not match table definition.
Unique Constraint
create table employees1(empno int primary key, empname varchar(20),job varchar(20) unique,salary
int,dept_no int);
output
Command(s) completed successfully.
insert into employees1 values(45,'Shyja','Asst Professor',28000,5);
insert into employees1 values(55,'Karthika','Professor',32000,9);
output
26
(1 row(s) affected)
(1 row(s) affected)
output
Violation of UNIQUE KEY constraint 'UQ__employees1__47FBA9D6'. Cannot insert duplicate key in
object 'dbo.employees1'.
The statement has been terminated.
Reason:The job must be unique but we entered as same job(professor) for Adlin.
output
Command(s) completed successfully.
output
(1 row(s) affected)
(1 row(s) affected)
27
output
The INSERT statement conflicted with the FOREIGN KEY constraint
"FK__employees__empno__49E3F248". The conflict occurred in database "master", table
"dbo.employees1", column 'empno'.
The statement has been terminated.
Reason: The empno should be same in both the relation ie, employees1 and employees2. But we entered
empno as 33, that is not in employees1 so it can’t accept in employees2.
Result
Thus the queries for constraints has been verified and executed successfully.
28
NESTED QUERIES
Ex.No: 6
Date:
Aim
To execute and verify the SQL Commands for Nested Queries.
Definition
Nested Query can have more than one level of nesting in a single query.
A subquery is a select from where expression that is nested within another query.
Subqueries are used to perform tests for set membership to make set comparisons and determine
set cardinality.
Set Memberships
Set Comparison
SQL uses various comparison operators such as <, <=,>, >=, =, <> , any, all and some , etc to
compare sets.
output
Command(s) completed successfully.
output
(1 row(s) affected)
(1 row(s) affected)
(1 row(s) affected)
(1 row(s) affected)
29
(1 row(s) affected)
output
Command(s) completed successfully.
output
(1 row(s) affected)
(1 row(s) affected)
(1 row(s) affected)
(1 row(s) affected)
(1 row(s) affected)
30
output
Command(s) completed successfully.
output
(1 row(s) affected)
(1 row(s) affected)
(1 row(s) affected)
(1 row(s) affected)
(1 row(s) affected)
IN:
select * from author where authorname in (select authorname from book1 where pubyear='2008');
31
NOT IN:
select title from book1 where authorname not in(select authorname from author where country
='Australia');
SET COMPARISON:
select title from book1 where price > all (select price from book where pubyear='2004')
select title from book1 where exists (select * from author where book1.authorname=author.authorname)
Result
Thus the above commands are executed and the output was verified successfully.
32
PROCEDURES
Ex.No: 7
Date:
Aim
To create a parameter for swapping two number and list down the table details.
Procedure definition
A procedure is a subprogram that performs a specific action. The syntax for creating a procedure
is given below:
Output
33
Procedure for update
output
output
34
begin
declare @output int;
if(@part='day')
begin
set @output=datediff(day,@birthday,getdate());
print 'you have survived'+convert(varchar(20),@output)+'days';
end
else if(@part='month')
begin
set @output=datediff(month,@birthday,getdate());
print'you have survived'+convert(varchar(20),@output)+'months';
end
else
begin
set @output=datediff(year,@birthday,getdate());
print'you have survived'+convert(varchar(20),@output)+'years';
end
end
output
Result
Thus the parameter for swapping two numbers are executed and the output was verified
sucessfully.
35
TRIGGER
Ex.No: 8
Date :
Aim
To implement the program using trigger.
Trigger Definition
A trigger is a statement that the system executes automatically as a side effect of a modification
to the database.
To design a trigger,
specify when a trigger is to executed.
Specify the actions to be taken when the trigger executes.
Example
Suppose a warehouse wishes to maintain a minimum inventory of each item. When the inventory
level of an item falls below the minimum level, an order should be placed automatically.
Program
36
insert into stock values(4,56,60,200);
insert into stock values(3,53,65,200);
insert into stock values(2,55,60,200);
insert into stock values(1,55,60,200);
Output
Table : Books
37
Table : Orders
Table: Order_list
Table: Stock
output
(1 row(s) affected)
ordered quantity not available
(1 row(s) affected)
[Reason:isbn=1, the book is dbms, its qty_instock is only 50 but we order for 60 books]
This order cannot insert into order_list. It is deleted automaticaaly.
output
(1 row(s) affected)
38
[This order is inserted into the order_list. The stock is 50 also we ordered for 50]
Result
Thus the trigger procedure has been executed sucessfully and the output was verified.
39
FUNCTION
Ex.No: 9
Date :
Aim
To write a functional procedure to find out the months,year and days you survived.
Function Definition
A function is a subprogram that computes a value.(It returns a single value.)
Function are similar to procedure but the difference is procedure should not return any value
but the function returns a value.
Syntax
create function <function name> [argument list] return datatype
(local declaration)
begin
(executable statements)
[exception]
(exception handler)
end;
Program
select dbo.sp_datediff('01-28-1984')
Output
For month
For days
40
begin
declare @lifespan int;
select @lifespan = datediff(day,@ip,getdate());
return @lifespan;
end
select dbo.sp_datediff('01-28-1984')
Output
Days Year
Result
Thus the function for days survived was executed and the output was verified successfully.
41
Ex.No:10 CREATE DATABASE USING XML
Date :
AIM:
STEPS:
Student.XML
<students xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<student id="101">
<rollno>101</rollno>
<name>John Doe</name>
<class>10th</class>
<marks>
<subject>Mathematics</subject>
<score>90</score>
</marks>
<marks>
<subject>Science</subject>
<score>85</score>
</marks>
<marks>
42
<subject>English</subject>
<score>95</score>
</marks>
<marks>
<subject>History</subject>
<score>80</score>
</marks>
<marks>
<subject>Geography</subject>
<score>75</score>
</marks>
</student>
<student id="102">
<rollno>102</rollno>
<name>Jane Smith</name>
<class>12th</class>
<marks>
<subject>Mathematics</subject>
<score>92</score>
</marks>
<marks>
<subject>Biology</subject>
<score>89</score>
</marks>
<marks>
<subject>Physics</subject>
43
<score>87</score>
</marks>
<marks>
<subject>Chemistry</subject>
<score>85</score>
</marks>
<marks>
<subject>English</subject>
<score>90</score>
</marks>
</student>
</students>
Student_db.xsd
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="students">
<xs:complexType>
<xs:sequence>
<xs:complexType>
<xs:sequence>
<xs:complexType>
44
<xs:sequence>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Result:
Thus the XML database is created and validated using XML schema
45
Ex.No:11 DOCUMENT,COLUMN AND GRAPH BASED DATABASE USING NOSQL
Date:
Aim:
To create document, column and graph based data using NOSQL database tools.
Procedure:
Once you connect to your deployment using MongoDB for VS code, use the left navigation to:
2. A MongoDB playground automatically opens with a template form to create a database and a
regular collection or a time series collection.
3. Fill in const database and const collection with names of your database and collection.
6. To run the playground, click the Play Button at the top right of the VS code navigation bar.
Code:
use('friends');
db.persons.drop();
db.friends.drop();
db.createCollection('persons');
db.createCollection('friends');
db.persons.insertMany([
46
{ _id: 'john', name: 'John' },
]);
db.friends.insertMany([
]);
47
$match: {
personId: person1,
},
$graphLookup: {
from: "friends",
startWith: "$friendId",
connectFromField: "friendId",
connectToField: "personId",
maxDepth: 2,
depthField: "depth",
as: "connections"
},
$set: {
degrees: {
$map: {
input: {
$filter: {
input: "$connections",
as: "conn",
},
48
as: "friends",
in: {
$sum: [
{ $toInt: "$$friends.depth" },
},
$set: {
degrees: {
$cond: [
"$degrees"
},
$unwind: "$degrees"
},
49
$group: {
_id: "$personId",
degrees: {
$min: "$degrees"
},
$project: {
_id: 0,
degrees: 1
]);
if (degrees) {
} else {
Output:
Result:
Thus the document, column and graph based data created using NOSQL database tools
50
Date :
Aim
To implement library management system.
Procedure
STEP 4: Place the command button and change their properties caption and name
In the pop-up window right click properties and select new table.
Give the table name, Using Add field add the required fields
Connect: access
EXECUTION CODE:
Data1.Recordset.AddNew
End Sub
51
Private Sub clear_Click()
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
End Sub
Data1.Recordset.delete
End Sub
Data1.Recordset.edit
End Sub
End
End Sub
Data1.Recordset.MoveFirst
End Sub
Data1.Recordset.MoveLast
End Sub
52
If (Data1.Recordset.EOF) Then
Data1.Recordset.MoveLast
Else
Data1.Recordset.MovePrevious
End If
End Sub
If (Data1.Recordset.BOF) Then
Data1.Recordset.MovePrevious
Else
Data1.Recordset.MoveLast
End If
End Sub
FORM DESIGN
OUTPUT
53
RESULT
Ex. No: 13
Date:
54
Aim
Backend Part
use railway
-------------------------------------------------------------------------------------------------------------------------------
--
create table reservation (id int primary key, name varchar(25), age int, sex char, add1 varchar(25),
add2 varchar(25), city varchar(25), state varchar(25), pin int, contactno bigint, trainid int, s_from
varchar(25), s_to varchar(25), tim time,dat date, cno int, seatno int,rid int)
create table train (id int primary key, name varchar(25), compartment int, seats int)
create table station (rid int foreign key(rid) references route, s_no int, s_name varchar(25))
create table route (id int foreign key(id) references train, rid int primary key, p_from varchar(25),
p_to varchar(25))
create table time (rid int foreign key(rid) references route, t_id int, s_no int, s_time time)
-------------------------------------------------------------------------------------------------------------------------------
--
55
insert into route values(2,4,'Nagarcovil','Karungal')
-------------------------------------------------------------------------------------------------------------------------------
--
create procedure insertion (@id int, @name varchar(25), @age int, @sex char, @add1 varchar(25),
@add2 varchar(25), @city varchar(25), @state varchar(25), @pin int, @contactno bigint, @trainid
int, @s_from varchar(25), @s_to varchar(25), @tim time, @dat date, @cno int, @seatno int,@nu int)
as
insert into reservation values(@id, @name, @age, @sex, @add1, @add2, @city, @state, @pin,
@contactno, @trainid, @s_from, @s_to, @tim, @dat, @cno, @seatno,@nu)
56
create procedure selection (@id int)
as
select * from reservation where id = @id
Form 1
57
create procedure getrid(@id int)
as
select rid from route where id = @id
create procedure getseat(@id int, @rid int, @s_name varchar(25), @time time, @dat date, @cno int)
as
begin
declare @s_no int, @t_id int
set @s_no = (select s_no from station where rid = @rid and s_name = @s_name)
set @t_id = (select t_id from time where rid = @rid and s_time = @time)
select seatno from vw_details where dat=@dat and cno=@cno and trainid=@id and rid = @rid and
t_id = @t_id and s_no >= @s_no
end
-------------------------------------------------------------------------------------------------------------------------------
--
Frontend Part
Form 1
58
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
Button1.Click
Form2.Show()
End Sub
Form 2
Form4.Show()
End Sub
End Clas
Form 2
Imports System.Data.SqlClient
Public Class Form2
Dim conn As SqlConnection
Dim mycomm As SqlCommand
Dim myreader As SqlDataReader
Dim s As Char
59
Dim id As Integer = 0
Dim s_no As Integer
60
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
Button2.Click
TextBox1.Text = id
TextBox2.Clear()
TextBox3.Clear()
TextBox4.Clear()
TextBox5.Clear()
TextBox6.Clear()
TextBox7.Clear()
TextBox8.Clear()
TextBox9.Clear()
TextBox10.Clear()
ClearCombobox()
End Sub
61
myreader = mycomm.ExecuteReader()
Do While myreader.Read()
ComboBox4.Items.Add(myreader.GetValue(0))
Loop
myreader.Close()
ComboBox5.Items.Clear()
mycomm.CommandText = "exec gettime'" & ComboBox2.Text & "','" & ComboBox3.Text &"'"
myreader = mycomm.ExecuteReader()
Do While myreader.Read()
ComboBox5.Items.Add(myreader.GetValue(0))
Loop
myreader.Close()
End Sub
62
End Sub
Form 3
Loop
myreader.Close()
End Sub
End Class
Form 3
Imports System.Data.SqlClient
Public Class Form3
Dim conn As SqlConnection
Dim mycomm As SqlCommand
Dim myreader As SqlDataReader
63
mycomm.Connection = conn
mycomm.CommandText = "exec get_id"
myreader = mycomm.ExecuteReader()
Do While myreader.Read()
ComboBox1.Items.Add(myreader.GetValue(0))
Loop
myreader.Close()
End Sub
Form 4
End Sub
End Class
Form 4
64
Imports System.Data.SqlClient
Public Class Form4
Dim conn As SqlConnection
Dim mycomm As SqlCommand
Dim myreader As SqlDataReader
Private Sub Form4_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
MyBase.Load
conn = New SqlConnection()
conn.ConnectionString = "Data Source=Samar-PC\SQLEXPRESS;Integrated
Security=True;database=railway"
conn.Open()
mycomm = New SqlCommand()
mycomm.Connection = conn
Dim c As Integer
With ListView1
.Clear()
.View = View.Details
.FullRowSelect = True
.GridLines = True
.FullRowSelect = True
.HoverSelection = True
.Scrollable = True
.Columns.Add("Id", 50, HorizontalAlignment.Left)
.Columns.Add("Name", 100, HorizontalAlignment.Left)
.Columns.Add("Age", 50, HorizontalAlignment.Left)
.Columns.Add("Sex", 50, HorizontalAlignment.Left)
.Columns.Add("Address Line 1", 100, HorizontalAlignment.Left)
.Columns.Add("Address Line 2", 100, HorizontalAlignment.Left)
.Columns.Add("City", 100, HorizontalAlignment.Left)
.Columns.Add("State", 100, HorizontalAlignment.Left)
.Columns.Add("Pin", 50, HorizontalAlignment.Left)
.Columns.Add("Contact no", 100, HorizontalAlignment.Left)
.Columns.Add("Train Id", 100, HorizontalAlignment.Left)
.Columns.Add("From", 100, HorizontalAlignment.Left)
.Columns.Add("To", 100, HorizontalAlignment.Left)
.Columns.Add("Date", 100, HorizontalAlignment.Left)
.Columns.Add("Cmp No", 100, HorizontalAlignment.Left)
.Columns.Add("Seat No", 100, HorizontalAlignment.Left)
.Columns.Add("Status", 100, HorizontalAlignment.Left)
End With
mycomm.CommandText = "exec selectall"
myreader = mycomm.ExecuteReader()
Do While myreader.Read()
ListView1.Items.Add(myreader.GetValue(0), 0)
65
ListView1.Items(c).SubItems.Add(myreader.GetValue(1))
ListView1.Items(c).SubItems.Add(myreader.GetValue(2))
ListView1.Items(c).SubItems.Add(myreader.GetValue(3))
ListView1.Items(c).SubItems.Add(myreader.GetValue(4))
ListView1.Items(c).SubItems.Add(myreader.GetValue(5))
ListView1.Items(c).SubItems.Add(myreader.GetValue(6))
ListView1.Items(c).SubItems.Add(myreader.GetValue(7))
ListView1.Items(c).SubItems.Add(myreader.GetValue(8))
ListView1.Items(c).SubItems.Add(myreader.GetValue(9))
ListView1.Items(c).SubItems.Add(myreader.GetValue(10))
ListView1.Items(c).SubItems.Add(myreader.GetValue(11))
ListView1.Items(c).SubItems.Add(myreader.GetValue(12))
ListView1.Items(c).SubItems.Add(myreader.GetValue(14))
ListView1.Items(c).SubItems.Add(myreader.GetValue(15))
ListView1.Items(c).SubItems.Add(myreader.GetValue(16))
If myreader.GetValue(16) <> 0 Then
ListView1.Items(c).SubItems.Add("Reserved")
Else
ListView1.Items(c).SubItems.Add("Cancelled")
End If
c += 1
Loop
myreader.Close()
End Sub
End Class
Result
Thus the VB.NET windows form application for Railway Reservation Management is created.
Date:
Aim
66
To create a VB.NET windows form application for Cop Friendly App-Eseva.
Sql.sql
USE FirApp;
67
);
GO
--- Functions
CREATE FUNCTION GetNextFIRNo()
RETURNS VARCHAR(10)
AS
BEGIN
DECLARE @nextFIRNo VARCHAR(10)
RETURN @nextFIRNo
END
GO
--- Procedures
CREATE PROCEDURE InsertPerson
@name VARCHAR(50),
@age INT,
@address VARCHAR(100),
@aadhar VARCHAR(20),
@mobile VARCHAR(15),
@gender VARCHAR(10),
@id INT OUTPUT
AS
BEGIN
SET NOCOUNT ON;
68
END
IF @aadhar IS NOT NULL AND EXISTS (SELECT 1 FROM Person WHERE aadhar = @aadhar)
BEGIN
RAISERROR('Aadhar number already exists', 16, 1)
RETURN
END
GO
IF (@person_id IS NULL)
BEGIN
RAISERROR('Complaint person ID cannot be NULL.', 16, 1);
RETURN;
END
IF (@description IS NULL)
BEGIN
RAISERROR('Description cannot be NULL.', 16, 1);
RETURN;
END
IF (@police_id IS NULL)
BEGIN
RAISERROR('Police ID cannot be NULL.', 16, 1);
RETURN;
END
69
SET @id = SCOPE_IDENTITY()
GO
IF @id IS NULL
BEGIN
RAISERROR('FIR ID cannot be NULL.', 16, 1);
RETURN;
END
UPDATE FIR
SET action_taken = @action_taken,
status_changed_by = @status_changed_by,
status = @status
WHERE id = @id;
GO
--- Triggers
CREATE TRIGGER trg_FIR_StatusChange
ON FIR
AFTER INSERT, UPDATE
AS
BEGIN
SET NOCOUNT ON;
IF UPDATE(status)
BEGIN
INSERT INTO CaseLog (fir_id, police_id, date, status)
SELECT inserted.id, inserted.police_id, GETDATE(), inserted.status
70
FROM inserted
END
END
GO
--- Views
CREATE VIEW CaseLogView
AS
SELECT cl.id AS CaseLogID, cl.date AS Date, f.id as FIRId, f.no AS FIRNo, p.name AS
PoliceOfficerName, cl.status AS Status
FROM CaseLog cl
INNER JOIN FIR f ON cl.fir_id = f.id
INNER JOIN Police p ON cl.police_id = p.id
GO
GO
GO
LoginForm.vb
Me.Hide()
Dim nextForm As New FirList()
nextForm.ShowDialog()
Me.Close()
Else
' Failed login, show error message
71
MessageBox.Show("Invalid police number or password", "Login failed",
MessageBoxButtons.OK, MessageBoxIcon.Error)
End If
End Sub
End Class
FirList.vb
Me.FIRListTableAdapter.Fill(Me.FirAppDataSet.FIRList)
End If
End Sub
End Class
FirForm.vb
72
If Not FirId.HasValue Then
TbActionTaken.Enabled = False
CbStatus.Enabled = False
Me.FirId = Nothing
CbStatus.SelectedItem = "Pending"
LblCaseNo.Text = SqlClient.Instance.GetNextFIRNo()
Else
LoadFir(FirId)
End If
End Sub
If AddPersonForm.NewPersonId.HasValue Then
CbPersonName.SelectedValue = AddPersonForm.NewPersonId
End If
End Sub
If String.IsNullOrEmpty(description) Then
MessageBox.Show("Please enter the case details.")
Return
End If
Try
FirId = SqlClient.Instance.InsertFir(personId, description, policeId)
TbActionTaken.Enabled = True
CbStatus.Enabled = True
CbPersonName.Enabled = False
TbCaseDetails.Enabled = False
73
MessageBox.Show("Error adding FIR. " & ex.Message)
End Try
Else
Dim actionTaken As String = TbActionTaken.Text.Trim()
Dim statusChangedBy As Integer = LoginForm.PoliceId
Dim status As String = CbStatus.Text.Trim()
Try
SqlClient.Instance.UpdateFir(FirId, actionTaken, statusChangedBy, status)
CaseLogViewTableAdapter.FillBy(Me.FirAppDataSet.CaseLogView, Me.FirId)
End Sub
Me.FirId = firId
CaseLogViewTableAdapter.FillBy(Me.FirAppDataSet.CaseLogView, firId)
End Sub
End Class
AddPersonForm.vb
74
Private Sub BtnAddPerson_Click(sender As Object, e As EventArgs) Handles BtnAddPerson.Click
Dim name As String = TbName.Text.Trim()
Dim age As Integer = Integer.Parse(TbAge.Text.Trim())
Dim address As String = TbAddress.Text.Trim()
Dim aadhar As String = If(String.IsNullOrEmpty(TbAadhar.Text.Trim()), Nothing,
TbAadhar.Text.Trim())
Dim mobile As String = TbMobileNo.Text.Trim()
Dim gender As String = CbGender.Text.Trim()
Dim id As Integer
Try
SqlClient.Instance.InsertPerson(name, age, address, aadhar, mobile, gender, id)
NewPersonId = id
Me.Close()
Catch ex As Exception
MessageBox.Show("An error occurred: " & ex.Message)
End Try
End Sub
ER DIAGRAM:
Screenshots:
75
76
77
Result
Thus the VB.NET windows form application for cop friendly app- Eseva is created.
78