dbms labv3 (1)
dbms labv3 (1)
No :1
DATE:
AIM:
To create a database and how to perform the operations and add constraints.
ALGORITHM:
PROGRAM:
1. CREATE
2. ALTER
3. DROP
4. TRUNCATE
5. COMMENT
6. RENAME
Table created.
3. View the table
structure: SQL>
Null? Type
EMPNO INT
ENAME CHAR(11)
POSITION VARCHAR
(8)
Table altered.
SQL> DESC
EMP;
EMPNO INT
ENAME CHAR(11)
POSITION VARCHAR(8)
Table altered.
SQL> DESC
EMP;
EMPNO INT
ENAME CHAR(11)
POSITION VARCHAR(8)
SALARY INT
Table altered.
Table altered.
Table altered
1. SELECT
2. INSERT
3. DELETE
4. UPDATE
1 row created.
(102,”KANNAN”,”PROFESSOR”,50000);
3. Display the records from
EMPLOYEE;
1 row updated.
1 row deleted.
SQL> CREATE TABLE CUSTOMERS( ID INT NOT NULL, NAME VARCHAR (20)
NONULL, AGE INT NOT NULL UNIQUE, ADDRESS CHAR (25) , SALARY DECIMAL (18, 2),
CUSTOMERS
ID
NAME
AGE
ADDRESS
Empty
CUSTOMERS
ID NAME AGE ADDRESS
1 Ramesh 32 Ahmedabad
2 Khilan 25 Delhi
3 kaushik 23 Kota
4 Chaitali 25 Mumbai
7. Primary Key:
SQL>CREATE TABLE CUSTOMERS( ID INT NOT NULL, NAME VARCHAR (20) NOT
NULL, AGE INT NOT NULL UNIQUE, ADDRESS CHAR (25) , SALARY DECIMAL (18,
2),PRIMARY KEY (ID) );
SQL>ALTER TABLE CUSTOMERS DROP PRIMARY KEY
; ID | NAME | AGE | ADDRESS | SALARY |
+ + + + + +
| 1 | Ramesh | 32 | Ahmedabad | 2000.00 |
| 2 | Khilan | 25 | Delhi | 1500.00 |
| 3 | kaushik | 23 | Kota | 2000.00 |
| 4 | Chaitali | 25 | Mumbai | 6500.00 |
| 5 | Hardik | 27 | Bhopal | 8500.00 |
| 6 | Komal | 22 | MP | 4500.00 |
| 7 | Muffy | 24 | Indore | 10000.00 |
+ + + + + +
RESULT:
The database was created using the various commands and constraints.
EX. NO :2
DATE:
AIM:
integrity.
ALGORITHM:
Creating a table for relating databases using constraints
PROGRAM:
CREATE DATABASE
employee_management; USE
employee_management;
Output
RESULT:
The database was created for relating between databases using the foreign key and referential
constraints.
EX.No:3
DATE:
AIM:
ALGORITHM:
program
SQL> select * from emp;
6 rows selected.
1) Avg (Average):
SAL=34250
2) Min (Minimum):
3) Max (Maximum):
SUM=205500
4)Count:
emp; COUNT-6
RESULT:
The employee database was created and aggregate functions were used.
EX.No:4
DATE:
AIM:
To create a database using Nested Queries, Sub Queries and different joins
ALGORITHM:
PROGRAM:
SQL> CREATE TABLE CUSTOMERS (ID INT NOT NULL, NAME VARCHAR (20) NOT NULL,AGE
INT NOT NULL, ADDRESS CHAR (25), SALARY DECIMAL (18, 2),
PRIMARY KEY (ID));
1. Sub Queries:
SQL> UPDATE CUSTOMERS SET SALARY = SALARY * 0.25 WHERE AGE IN (SELECTAGE FROM
CUSTOMERS_BKP WHERE AGE >= 27);
+ + + + + +
| ID | NAME | AGE | ADDRESS | SALARY |
+ + + + + +
| 1 | Ramesh | 35 | Ahmedabad | 125.00 |
| 2 | Khilan | 25 | Delhi | 1500.00 |
| 3 | kaushik | 23 | Kota | 2000.00 |
| 4 | Chaitali | 25 | Mumbai | 6500.00 |
| 5 | Hardik | 27 | Bhopal | 2125.00 |
| 6 | Komal | 22 | MP | 4500.00 |
RIGHT JOIN:
ID | NAME | SALARY |
| 2 | Ramesh | 1500.00 |
| 2 | kaushik | 1500.00 |
| 1 | Chaitali | 2000.00 |
| 2 | Chaitali | 1500.00 |
| 3 | Chaitali | 2000.00 |
| 6 | Chaitali | 4500.00 |
| 1 | Hardik | 2000.00 |
| 2 | Hardik | 1500.00 |
| 3 | Hardik | 2000.00 |
| 4 | Hardik | 6500.00 |
| 6 | Hardik | 4500.00 |
| 1 | Komal | 2000.00 |
| 2 | Komal | 1500.00 |
| 3 | Komal | 2000.00 |
| 1 | Muffy | 2000.00 |
| 2 | Muffy | 1500.00 |
| 3 | Muffy | 2000.00 |
| 4 | Muffy | 6500.00 |
| 5 | Muffy | 8500.00 |
| 6 | Muffy | 4500.00 |
RESULT:
The database was created for relating between databases using the joins and sub queries.
EX.No:5
DATE:
AIM:
ALGORITHM:
PROGRAM:
NATURAL JOIN:
SQL>CREATE TABLE customer ( id INT AUTO_INCREMENT PRIMARY KEY, customer_name
VARCHAR( 55), account int, email VARCHAR(55));
Table Created
Table Created
Customer
id customer_name account email
1 Stephen 1030 [email protected]
2 Jenifer 2035 [email protected]
3 Mathew 5564 [email protected]
4 Smith 4534 [email protected]
5 David 7648 [email protected]
Balance
id accoun balance
t
1 1030 50000
2 2035 230000
3 5564 125000
4 4534 80000
5 7648 45000
EQUI JOIN:
id class city
93 Delhi
10 2 Delhi
12 2 Delhi
Gouri 6 2 Delhi
Hina 3 2 Delhi
Megha 4 2 Delhi
Gouri 6 2 Delhi
name id city
Hina 9 Delhi
Megha 9 Delhi
Gouri 9 Delhi
Hina 10 Delhi
Megha 10 Delhi
Gouri 10 Delhi
Hina 12 Delhi
Megha 12 Delhi
Gouri 12 Delhi
SQL>CREATE TABLE college ( id INTEGER, classTeacher TEXT NOT NULL, Strength TEXT
NOT NULL);insert some values INSERT INTO college VALUES (1, 'Alpha', '50'); INSERT
INTO college VALUES (2, 'Romeo', '60');INSERT INTO college Values (3, 'Charlie', '55');
Class Teacher
Id Alpha 1
Romeo 2
Charlie 3
RESULT:
The database was created for relating between databases using the joins and sub queries.
EX.No:6
DATE:
AIM:
Algorithm:
Function:
SQL>delimiter $$
>Create function func1 (str varchar(20))
>return char(50)
>return CONCAT(‘WELCOME TO’, str)
>end $$
>delimiter $$
>select func1(‘DBMS LAB’);
>$$
Procedure:
EXECUTE calculate_average;
regno name mark1 mark2 mark3 mark4 mark5 total average
101 priya 78 88 77 60 89 392 78.4
102 karthi 99 77 69 81 99 425 85
103 karthipriya 100 90 97 89 91 467 93.4
RESULT:
Thus the program for creation of procedure is executed successfull
EX.No:7
DATE:
AIM:
To execute DCL and TCL Commands.
Algorithm:
Step 1: Start a program
Step 2: Enter the input
Step 3: Execute the TCL abd DCL commands.
Step 4: Stop the program
SQL> commit;
Commit
complete.
Table created.
SQL> insert into goods values(&sno,&itemcode,'&itemname',&cost);
Enter value for sno:1
Enter value for itemcode: 1025
Enter value for itemname: dell moniters
Enter value for cost: 5000
old 1: insert into goods values(&sno,&itemcode,'&itemname',&cost) new 1: insert into goods
values(1,1025,'dell moniters',5000)
SQL> insert into goods
values(&sno,&itemcode,'&itemname',&cost);
Enter value for sno: 1
Enter value for itemcode: 1025
Enter value for itemname: moniter
Enter value for cost: 5000
old 1: insert into goods values(&sno,&itemcode,'&itemname',&cost)
new 1: insert into goods values(1,1025,'moniter',5000)
1 row created.
SQL> /
Enter value for sno: 2
Enter value for itemcode: 1026
Enter value for itemname: mouse
Enter value for cost: 250
old 1: insert into goods values(&sno,&itemcode,'&itemname',&cost)
new 1: insert into goods values(1026,1026,'mouse',250)
1 row created.
SQL> /
Enter value for sno: 3
Enter value for itemcode: 1027
Enter value for item name: RAM
Enter value for cost: 1500
old 1: insert into goods values(&sno,&itemcode,'&itemname',&cost)
new 1: insert into goods values(3,1027,'RAM',1500)
1 row created.
SQL> /
Enter value for sno: 4
Enter value for itemcode: 1028
Enter value for itemname: webcam
Enter value for cost: 350
old 1: insert into goods values(&sno,&itemcode,'&itemname',&cost)
new 1: insert into goods values(4,1028,'webcam',350)
1 row created.
SQL> /
Enter value for sno: 5
Enter value for itemcode: 1029
Enter value for itemname: pendrive
Enter value for cost: 500
old 1: insert into goods values(&sno,&itemcode,'&itemname',&cost)
new 1: insert into goods values(5,1029,'pendrive',500)
1 row created.
SQL> commit;
Commit complete.
3. Write a query to add the record into the table “goods” and set the Savepoint S1, S2 and
S3 and verify it.
9 rows selected.
Write a query to Rollback to Save point S2 and verify it.
SQL> rollback to save point s2;
Rollback complete.
DCL Commands:
Grant:
GRANT SELECT, UPDATE ON MY_TABLE TO SOME_USER, ANOTHER_USER;
RESULT:
Thus the TCL and DCL commands in SQL is successfully executed
EX.No:8
DATE:
AIM:
Algorithm:
Program:
Delimiter $$
create trigger update_trigger before update on account for each row
begin
if new.sum=50 then set new.sum=100;
else if new. Sum>50 then set new.sum=200;
end if;
end$$
Output function:
delimiter $$
MySQL> update account set sum=50
$$ select * from account;
-> $$
OUTPUT:
+ ++
| sum | amount |
+ ++
| 100 |20 |
| 100 |30 |
| 100 |40 |
RESULT:
Thus the program for creation of triggers and functions is executed successfully.
EX.No:9
DATE:
AIM:
To Create views and index for database tables.
PROGRAM:
6 rows selected.
EMPNO NUMBER(4)
PH_NO NUMBER(8)
SQL> select * fromemp;
EMPNOPH_NO
3737 225301
4545 485565
6544 789663
7575 896652
6555 987777
CREATE VIEW
View created from more than one table leading to ‘Read Only’ view.
Priya 225301
priya 485565
santh 789663
Karthi 896652
INDEX:
UNIQUE INDEX
Index created
ALTER AN INDEX
Index altered
DROP INDEX
Index Dropped
RESULT:
Thus, the database views and indexes were successfully executed.
EX.No:10
DATE:
AIM:
ALGORITHM:
a new XML file (on the File menu, point to New, and then click File).
3. Add the following data to the XML document to represent a product in a catalog:
<Product ProductID="123">
<ProductName>Rugby jersey
</ProductName>
</Product>
4. Save the file as Product.xml in a folder that you will be able to readily access later.
1. In Visual Studio 2005 or in Visual Studio .NET, point to New on the File
4. Save the file as Product.dtd in the same folder as your XML document.
5. Reopen Product.xml in Visual Studio 2005.
3. Add the following XDR schema definitions to the file to describe the grammar of the XML document:
<?xml version="1.0"?>
<Schema name="ProductSchema"
xmlns="urn:schemas-microsoft-com:xml-data"
xmlns:dt="urn:schemas-microsoft-com:datatype
s">
4. Save the file as Product.xdr in the same folder as your XML document.
5. Reopen the original Product.xml, and then link it to the XDR schema, as follows:
1. In Visual Studio .NET, point to New on the File menu, and then click File.
2. Select the Text File type, and then click Open.
3. Add the following XSD schema definition to the file to describe the grammar of the XML document:
<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="Product">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="ProductName" type="xsd:string"/>
</xsd:sequence>
<xsd:attribute name="ProductID" use="required" type="xsd:int"/>
</xsd:complexType>
</xsd:element>
</xsd:schema>
4. Save the file as Product.xsd in the same folder as your XML document.
5. Reopen the original Product.xml, and then link it to the XSD schema, as follows:
<?xml version="1.0" encoding="utf-8" ?>
<Product ProductID="123"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-inst
ance" xsi:noNamespaceSchemaLocation="Product.xsd">
<ProductName>Rugby jersey</ProductName>
</Product>
6. Save the modified XML document as ProductWithXSD.xml.
2. Save ProductWithXSD.xml.
3. Open Product.xsd, click the XML tab, and then modify the xsd:schema start tag as follows,
so that the schema applies to the namespace urn:MyNamespace:
<xsd:schema
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="urn:MyNamespace"
elementFormDefault="qualified">
4. Save Product.xsd.
5. Run the application to validate the XML document by using the XSD schema.
0utput:
<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="Product">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="ProductName" type="xsd:string"/>
</xsd:sequence>
<xsd:attribute name="ProductID" use="required" type="xsd:int"/>
</xsd:complexType>
</xsd:element>
</xsd:schema>
</Product>
RESULT:
The xml database was successfully created by display the web page of validate xml schema
EX.No:11
Execute complex transactions and realize DCL and TCL
DATE: commands.
AIM:
To Create document, column and graph based data using NOSQL database tools
PROGRAM:
Create Database:
>use javatpointdb
Swithched to db javatpointdb
>db
Insert a document:
>db.movie.insert({"name":"javatpoint"})
db.javatpoint.insert(
{
course:
"java",
details: {
duration: "6 months",
Trainer: "Sonoo
jaiswal"
},
Batch: [ { size: "Small", qty: 15 }, { size: "Medium", qty: 25 } ],
category: "Programming language"
}
)
WriteResult({ "nInserted": 1})
Drop Database:
> db.dropDatabase()
1} Create collection :
>db.SSSIT.insert({"name" : "seomount"})
>show
collections SSSIT
db.collection_name.find()
Neo4j CQL
Create
nodes:
Open the localhost on the browser: http://localhost:7474/browser/ and use the following code:
CREATE (single);
MATCH (n) RETURN (n)
AIM:
SAMPLE CODE:
Dim db As
Database Dim rs As Recordset
Private Sub
cmdADD_Click()
rs.AddNew DtPicker
DOJ.Enabled = True
txtEmpID.Enabled =
True
txtFirstName.Enabled =
True txtLastName.Enabled =
True txtAddress.Enabled =
True txtDOJ.Enabled = True
txtSalary.Enabled = True
txtEmpID.SetFocus
txtEmpID.Text = ""
txtFirstName.Text = ""
txtLastName.Text = ""
txtAddress.Text = ""
txtDOJ.Text=Date
txtSalary.Text =""
txtHRA.Text = ""
txtDA.Text = ""
txtTA.Text =
"" txtPF.Text=
""
txtGrossPay.Text = ""
txtNetPay.Text = ""
cmdEdit.Enabled=False
cmdSubmit.Enabled = False
cmdCalculate.Enabled=
Private Sub
cmdCalculate_Click()If
project"txtSalary.SetFocus Else
txtHRA.Text = 0.15 *
* Val(txtSalary.Text) txtTA.Text =
= 0.05 * Val(txtSalary.Text)
Else
Cancel=False
rs.Delete
Project" ClearALL
Else
Cancel=True
End If
'rs.MoveNex
t End If
End Sub
txtFirstName.Enabled = True
txtLastName.Enabled = True
txtAddress.Enabled = True
txtDOJ.Enabled = True
txtSalary.Enabled= True
rs("FIRSTNAME")
txtFirstName.Textrs("LASTNAME")
txtLastName.Text rs("ADDRESS")
txtAddress.Text
rs("DATEOFJOINING") = txtDOJ.Text
rs("SALARY") =txtSalary.Text
rs("HRA") = txtHRA.Text
= txtTA.Text
Cancel=False
End
Else
Cancel=True
End If
End Sub
Private Sub
cmdFirst_Cli
ck()
rs.MoveFirst
cmdPrev.Ena
bled = False
cmdFirst.En
abled = False
cmdNext.Enabled =
True cmdLast.Enabled =
True cmdEdit.Enabled =
True GetData
End Sub
Private Sub cmdLast_Click()
rs.MoveLast cmdFirst.Enabled = True
cmdPrev.Enabled = True
cmdNext.Enabled = False
cmdLast.Enabled = False
cmdEdit.Enabled = True
GetData
End Sub
cmdEdit.Enabled = True
cmdFirst.Enabled = True
cmdPrev.Enabled=True
rs.MoveNext
If rs.EOF = True
Then
cmdNext.Enabled=False
e cmdLast.Enabled = False
MsgBox "LAST RECORD", vbInformation, "Employees Project" rs.MoveLast
Else GetData
End If
End Sub
Private Sub cmdPrev_Click() cmdEdit.Enabled =
True cmdFirst.Enabled = True
cmdNext.Enabled =
True cmdLast.Enabled =
True rs.MovePrevious
If rs.BOF = True
Then
cmdFirst.Enabled = False
cmdPrev.Enabled = False
MsgBox "FIRST RECORD", vbInformation, "Employees Project"
rs.MoveFir
st Else
GetData
End If
GetData
End
Sub
Private Sub
cmdReport_Click()
DataReport1.Show
End Sub
Private Sub
cmdSubmit_Click() On
rs("EMPID")=txtEmpID.Text
rs("FIRSTNAME") = txtFirstName.Text
rs("LASTNAME") = txtLastName.Text
rs("ADDRESS") = txtAddress.Text
rs("DATEOFJOINING") = txtDOJ.Text
rs("SALARY") = txtSalary.Text
rs("HRA") = txtHRA.Text
rs("DA") = txtDA.Text
rs("TA") = txtTA.Text
rs("PF") = txtPF.Text
rs("GROSSPAY") =txtGrossPay.Text
rs("NETPAY") =txtNetpay.Text
Private Sub
txtAddress_Change()
cmdSubmit.Enabled = True
End Sub
Private Sub
txtDOJ_Change()
cmdSubmit.Enabled =
[Private Sub
txtEmpID_Change()
cmdSubmit.Enabled = True
End Sub
KeyAscii = 0
Private Sub
txtFirstName_Change()
cmdSubmit.Enabled = True
End Sub
Private Sub
txtLastName_Change()
cmdSubmit.Enabled = True
End Sub
Private Sub
txtSalary_Change() If
If TypeOf ctrl Is
TextBox Then
ctrl.Text = ""
Next End Sub
If rs.RecordCount <> 0
Then
txtEmpID.Text = rs("EMPID")
txtFirstName.Text = rs("FIRSTNAME")
txtLastName.Text = rs("LASTNAME")
txtAddress.Text = rs("ADDRESS")
txtDOJ.Text = rs("DATEOFJOINING")
txtSalary.Text = rs("SALARY")
txtHRA.Text = rs("HRA")
txtDA.Text = rs("DA")
txtTA.Text = rs("TA")
txtPF.Text=rs("PF")
txtGrossPay.Text = rs("GROSSPAY")
txtNetPay.Text = rs("NETPAY")
txtEmpID.Enabled = False
txtFirstName.Enabled =
False txtLastName.Enabled =
False txtAddress.Enabled =
False
txtDOJ.Enabled = False
txtSalary.Enabled = False
txtHRA.Enabled = False
txtDA.Enabled= False
txtTA.Enabled = False
txtPF.Enabled = False
txtGrossPay.Enabled =False
txtNetPay.Enabled = False
cmdSubmit.Enabled =
False
cmdCalculate.Enabled=Fals
DtPickerDOJ.Enabled=False
Else
txtEmpID.Enabled = False
txtFirstName.Enabled =
False txtLastName.Enabled =
False txtAddress.Enabled =
False txtDOJ.Enabled = False
txtSalary.Enabled = False
txtHRA.Enabled = False
txtDA.Enabled = False txtTA.Enabled = False txtPF.Enabled = False
txtGrossPay.Enabled = False
txtNetPay.Enabled = False c
mdSubmit.Enabled = False
cmdCalculate.Enabled = False End If
End Sub
PrivateSubtxtSalary_KeyPress(KeyAsciiAs
Integer)
If (KeyAscii < 48 Or KeyAscii > 57) Then
KeyAscii = 0
cmdADD.Enabled = True
cmdCalculate.Enabled =
False cmdSubmit.Enabled =
False
DATABASE IN MS ACCESS:
FORMS WHILE EXECUTION:
RESULT:
Thus the Student Personal Information System is successfully designed using PHPwith mysql as backend.
EX.NO:13
DATE:
AIM:
To create a database for E-mart Grocery shop and apply all sql properties.
SAMPLE CODE:
Cross join:
select *
from grocery_visit
cross join dept_store_visit
and dept_store_visit.amount_spent > 15;
RESULT:
Thus the E-mart Grocery Shop is successfully designed.