Sei sulla pagina 1di 2

SQL Tutorial (Stage-1)

Assume you have to create a table named EMP and perform some operations on it. Let the structure of this table as: Field/Column Name EmpID EmpName DOB salary Dept Type Integer string datetime double string Size 5 30 7,2 10

Table Creation
To create this table in SQL Server, use the following SQL Command Create Table Emp ( EmpID integer, EmpName varchar(30), DOB datetime, Salary decimal(7,2), Dept varchar(20) )

Note: SQL is case insenstive language for example Create can be wrtting as CREATE or create or CreATE; it doest Matter.

Insert Data in the Table


To insert data in this table use, the following SQL Command Insert into Emp values(1001,'Mohit','12/10/1981',8900.50,'HR') Note: Data should be given in the same sequence as field sequence in the table for example here sequence is EmpID, EmpName,DOB,Salary,Dept value are in the same seq 1001 for EmpID Mohit for EmpName and so on

Update Data in the Table


To modify or update data in this table use, the following SQL Command Update Emp set Name = 'Mohit Sharma', Salary = 9550 where EmpID = 1001 Here name will become Mohit Sharma and salary 9550 for the employee whose ID is 1001

Delete Data in the Table


To delete data in this table use, the following SQL Command Delete from Emp where EmpID = 1001 Here record of employee whose ID is 1001 will be deleted

To Select Data from the Table


To select required data from this table use, the following SQL Command Select * from Emp All the data (all columns and all records) from Emp table will be seleted and returned Select * from Emp where EmpID = 1001 For Employee ID = 1001, record (all columns) will be seleted from Emp table

Select Name, Salary from Emp where EmpID = 1001 For Employee ID = 1001, name and salary will be seleted from Emp table

To Delete Table
To delete table from, the following SQL Command Drop table Emp

Potrebbero piacerti anche