Dive into some SQL queries

In my 7th semester Level-3 Term -1 of my  BSc. Engineering course of Computer Science and Engineering in Daffodil International Univeristy(DIU) I am doing a course named Database Management System

Here our course teacher is using MS SQL Server 2008. I am sharing here what i have learnt from my class.

SQL stands for structured query language which help us to manage database easily

To create database in sql
Suppose a databse for university student

create database university;

where we will create a table named student

create table university.dbo.student(sid int,sname varchar(20),age int);

after this we can show the empty table by this query

select * from university.dbo.student;

 

Now by this query  we will insert data into the table

insert into university.dbo.student values(01,'Zaki Live',22);
insert into university.dbo.student values(02,'Zaki',23);
insert into university.dbo.student values(03,'Live',24);
insert into university.dbo.student values(04,'Mobin',21);
insert into university.dbo.student values(05,'Rahim',20);
insert into university.dbo.student values(06,'Rajdip',22);
select * from university.dbo.student;

Don’t forget to use values.It is actually SQL syntax and don’t forget to give
select * from statement at the end of the query as it will help to display the updated table where star or asterisks sign * means all info of this table

if we want to show some limited data from all then here is one example

select * from university.dbo.student where sid=3;

 

select sname,age from university.dbo.student where sid=3;

Now I am going to update some of my data in the table then

update university.dbo.student set sname='Rocky Live Dhaka !' where sid=3;
select*from university.dbo.student;

2015-01-27 00_51_59-
Now I am going to delete some data from the table

delete from university.dbo.student where age=22 or age=23;
select * from university.dbo.student;

 

2015-01-27 00_56_50-

Then here see the change.Age name with 22 and 23 have been deleted for this sql command.

We have used here OR statement because AND is not working in MS SQL Server 2008.I don’t know why…May be I don’t know the actual things about and/or in MS SQL. I apologize for this..

If this tutorial helped you to understand the basics of the sql query.Then don’t forget to keep soem comment below.

Thanks for reading 🙂

It would be a great help, if you support by sharing :)
Author: zakilive

Leave a Reply

Your email address will not be published. Required fields are marked *