0% found this document useful (0 votes)
2 views3 pages

1 SQL Basic Operations

The document provides SQL queries for creating a 'Students' table and performing various operations such as inserting, updating, and deleting records. It includes the creation of the table with fields for student number, name, age, and department, followed by multiple insertions of student records. Additionally, it demonstrates updating a student's department and deleting a record, along with select queries to display the current state of the table.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views3 pages

1 SQL Basic Operations

The document provides SQL queries for creating a 'Students' table and performing various operations such as inserting, updating, and deleting records. It includes the creation of the table with fields for student number, name, age, and department, followed by multiple insertions of student records. Additionally, it demonstrates updating a student's department and deleting a record, along with select queries to display the current state of the table.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

1.

Write a SQL query for creating Table, and SQL queries for
inserting, deleting, updating the records in Table.

mysql> CREATE TABLE Students (sno INT PRIMARY KEY, sname


VARCHAR(50) NOT NULL, age INT, dept VARCHAR(10));

Query OK, 0 rows affected (0.00 sec)

mysql> desc students;

Field Type Null Key Default Extra


sno int(11) NO PRI NULL
varchar(50
sname NO NULL
)
age int(11) YES NULL
varchar(10
dept YES NULL
)
4 rows in set (0.00 sec)

mysql> INSERT INTO Students(sno, sname, age, dept) VALUES (10101,


'Dharani', 19, 'CS') ;

Query OK, 1 row affected (0.00 sec)

mysql> INSERT INTO Students (sno, sname, age, dept) VALUES


(10102,'Priya',19,'ai');

Query OK, 1 row affected (0.00 sec)

mysql> INSERT INTO Students (sno, sname, age, dept) VALUES


(10103,'Jenita',20,'ai');

Query OK, 1 row affected (0.00 sec)

mysql> INSERT INTO Students (sno, sname, age, dept) VALUES


(10104,'Deepika',20,'ai');

Query OK, 1 row affected (0.00 sec)

mysql> INSERT INTO Students (sno, sname, age, dept) VALUES


(10105,'Subasri',20,'ai');

Query OK, 1 row affected (0.00 sec)

mysql> select * from Students;


sno sname age dept
10101 Dharani 19 CS
10102 Priya 19 ai
10103 Jenita 20 ai
10104 Deepika 20 ai
10105 Subasri 20 ai
5 rows in set (0.00 sec)

mysql> update Students set dept='ai' where sno=10101;

Query OK, 1 row affected (0.02 sec)

Rows matched: 1 Changed: 1 Warnings: 0

mysql> select * from Students;

sno sname age dept


10101 Dharani 19 ai
10102 Priya 19 ai
10103 Jenita 20 ai
10104 Deepika 20 ai
10105 Subasri 20 ai
5 rows in set (0.00 sec)

mysql> select * from Students where age=20;

sno sname age dept


10103 Jenita 20 ai
10104 Deepika 20 ai
10105 Subasri 20 ai
3 rows in set (0.00 sec)

mysql> select * from Students where age=20;


sno sname age dept
10103 Jenita 20 ai
10104 Deepika 20 ai
10105 Subasri 20 ai
3 rows in set (0.00 sec)

mysql> delete from Students where sno=10105;

Query OK, 1 row affected (0.00 sec)

mysql> select * from Students;

sno sname age dept


10101 Dharani 19 ai
10102 Priya 19 ai
10103 Jenita 20 ai
10104 Deepika 20 ai
4 rows in set (0.00 sec)

You might also like