Loading...

Table is a SQL Server object that is used to store related data or information. In table data is logically organized in rows and column format. 

How to create table 

Creating table by SQL Query: 

Create table <<Table_Name>>
(
<<Column_Name1>>  <<DataType>, 
<<Column_Name2>>  <<DataType>, 
<<Column_Name3>>  <<DataType>
)


        EX: 

Create table Student
(
ID int,
StudentName varchar(50),
RollNumber int,
ClassID int
)

  
Before creating table you should know about datatype in SQL Server. So, to read about datatypes in SQL Server go to this link. Datatypes in SQL Server


We have created new table Student. And now we are going to insert data in Student table.
Syntex for inserting new record in SQL Server table is:

Insert into <<Table_Name>> (<<Column_Name1>>,<<Column_Name2>>,<<Column_Name3>>)
                                          values (<<Value1>>,<<Value2>>,<<Value3>>)
 
Ex. 
insert into Student (StudentID,Name,RollNo,ClassID) values (1,'Ramesh Kumar',1,10)

after executing this SQL Query we will receive message that how many rows are effected in table like (1 row(s) 
affected)


Now we will look how we can retrieve or get inserting record from SQL Server table.
We will write a simple SQL Query to get all the records in table.

Select * from <<Table_Name>>

Ex. 
Select * from Student 



Here we see all the data of student table. But if we want to see only specific information of all Student then we will write a SQL Query like 

Select <<Column_Name1>>,<<Column_Name2>> from <<Table_Name>>

Ex. 
select StudentId, Name from Student


Finally we will see the result of above SQL Query.