Here are the Steps:
Step 1: Open your SQL Server 2008 and connect it by using suitable method that you had chosen at the time of installation that is “Window Authentication” or “Mixed Mode”.
After connecting, you will see something like the following image, where there are lots of options available in the object explorer [left side]. Click on New Query.
Step 2: Create Database.
Create database student
To run this Query just select the whole Query and Press F5. You will see under the database a new Database is generated with the name of student. If you can’t see your database, then just press the refresh button inside the object explorer.
Output:
Step 3: Create Table inside the Student Database.
Create Table
- use student
-
- create table tbl_student1
- (
- id int IDENTITY(1,1)PRIMARY KEY NOT NULL,
- name varchar(50) NULL,
- city varchar(50) NULL
- )
Run this query by pressing F5 and you will see in object explorer under Student Database, Table dbo.tbl_student1 name table gets created. You can check out by right clicking on that table, then Design, it will show you the design view of the table.
Output: Step 4: Now we will insert some data into out table tbl_student.
Insert Query insert into tbl_student1(name,city)values('Nilesh','Rajkot'),('Purnima','Pune'),('Rinku','Delhi')
,('Suhag','Mysore'),('Indrajeet','Kota'),('Shailesh','Chennai'),('Chandni','Kolkata')
Output: Step 5: Now we will write update query, suppose by chance if you entered a wrong data into the table, at that time you can’t delete the data as it will delete the relevant field and it will affect in other table too if the table is in relation with other. We will update the data of id = 2.
Update Query - update tbl_student1
- set
- name='Rohit',
- city='Shimla'
- where id =2
Output: Step 6: Delete the Data from the table.
Delete the Data
We will delete the data of id=5.
delete from tbl_student1
where id=5
Output: You can use drop for dropping your whole table. There are other queries too that I’ll cover up in the other sections of SQL.