How to Create Database in SQL Server 2008

Hello friends. Today I am sharing my article about how to create databases, create tables, insert values into tables and update, delete and so on. I know this is basic information but I know this article will be helpful for all beginner students.

You need to first install .Net and then you need to install Microsoft SQL Server, any version. I have installed SQL Server 2008 .



After installation, connect to the database as shown in the following image.



Now SQL Server is ready to create your database as shown in the following image.


  1. create database School2;    /*School2 database name*/  
  2.   
  3. use school2;   /*use query for select database*/   
  4.   
  5. Create table Student   /* create table_Name(Student)*/  
  6. (  
  7.    Batch varchar(25)not null,  
  8.    Reg_No Varchar (25) primary key not null,  
  9.    Course varchar(20)not null,  
  10.    Name_ varchar(15) not null,  
  11.    Last_Name varchar(10) not null,  
  12.    Fahter_Name varchar(18)not null,   
  13.    Age int not null,  
  14.    Sex varchar(8) not null,  
  15.    Parent_Mo_No Bigint not null,  
  16.    Student_Mo_no Bigint not null,  
  17.    Nationality varchar(15) not null,  
  18.    State varchar(15) not null,  
  19.    City varchar(15) not null,  
  20.    Local_Address varchar(30) not null,  
  21.    Pin_Code bigint not null,  
  22.    Parent_Occupation varchar(15) not null,  
  23.    Total_Rs int not null,  
  24.    Date_ datetime  
  25. );  
  26. select * from Student;    /* select * form means show all data form table*/  
  27.   
  28. insert into student values('LLB_08_2ndy','776678','LLB','Vivekanand','Singh','Dineshwar singh',23,'Male',9891688420,9968022717,'Indian','Bihar','Patna','Ny 26A',800001,'Gov job',90000,5/12/1986);  
  29.   
  30. insert into student values('BA_1stYear','776683','Pol Science','Rajat','Singh','Suman Singh',23,'Male',9565434560,9716157368,'Indian','Delhi','New Delhi','Mahipalpur New Delhi',110037,'Businessman',70000,5/05/2015)  
  31.   
  32. delete from Student where Student_Mo_no='9540434299'; /* Delete query use for delete insert recored form table */  
  33.   
  34. update student set Date_ =04/04/2015 where Reg_No='776678'; /*update query use for update in existing data add new data*/ 

More select query using conditional expression

  1. select * from Student where Total_Rs=7000;     /*this quary based on search particular details using where clause...*/  
  2.   
  3. select * from Student  
  4. where Course ='cs'     
  5. AND Reg_No ='776679';     /*AND Operator using this quary both condition true then value will print.*/  
  6.   
  7. select * from Student  
  8. where Last_Name ='rajput'  
  9. OR Reg_No='776679';      /*OR Operator using this quary if any condition will true value will print if both are true both value print.*/  
  10.   
  11.   
  12. select * from student  
  13. where State ='bihar'  
  14. AND(Reg_No ='776678' OR Reg_No='776679');  /*this quary using both AND & OR Operator print value only AND Operator*/ 



A constraint is a condition or check for an application on a field or set of fields.

  • Delete is a DML command and drop is a DDL command
  • Delete is used to delete rows from a table whereas drop is used to remove the entire table or database from the database.
  • Update is a DML command and alter is a DDL command
  • Update is used to update data in an existing table

So friends, this is a small article that will help you with "How to Create a Database in SQL Server 2008".

Next time I will provide more interesting commands. Thank you. I Hope this is helpful for you. Enjoy, :)

Thanks in advance,
Krishna Rajput

Up Next
    Ebook Download
    View all
    Learn
    View all