Q) What is ‘SQL’?

A) SQL stand for Structured query language. Its a standard language for storing, retrieving and manipulating data in databases.


Q) What are the data types in SQL sever??

A) A data type specifies type of data allowed in a column. The following are the datatypes in SQL server:

1.String Datatypes
2.Integer/Decimal Datatypes
3.Currency Datatypes
4.Date and Time Datatypes
5.Binary/VarBinary Datatypes


Q) What are String Datatypes in SQL Server?

A) The following are the string datatypes:

  1. Char
  2. Varchar
  3. Varchar(max)
  4. nVarchar

Q) What are Integer Datatypes in SQL Server?

A) The following are the string datatypes: .

  1. TinyInt
  2. SmallInt
  3. Int
  4. BigInt
  5. Decimal

Q) Why do we use binary or varBinary datatype?

A) Binary and varBinary datatypes are used to save images and documents in binary format.


Q) Creating table syntax in SQL Server

A) Creating table syntax in sql server:

Create table <TableName>
 (
ColName Datatype(size),
ColName2 Datatype(size)
 )

Example:
Create table Employee(EmpNo smallint,
EmpName varchar(20),Sal smallMoney,
HiredDate Date)

Q) What are Rules for Creating tables in SQL Server?

A) Tablename should start with alphabet

Table name should not contain spaces and special characters

Table name should not be a SQL Server keyword

Table name can contain a maximum 128 chars.


Q) Inserting Data into table

A) “Insert” command is used to insert data into data tables.

Syntax: 
Insert into <Tablename>(Col1Name,Col2Name)
	values(Col1Value,Col2Value)

Example:
Insert into Employee(EmpName, Sal, HiredDate)
values('Mak',3000,getdate())

Q) How to retrieve data from table?

A) “Select” command is used to retrieve data from database.

Syntax: 
Select <column1>,<column2>,<column3> from <tablename>

Example:
Select EmpName,Sal,HiredDate from Employee

Note: To display all columns in table use (*)
Example: Select * from Employee


Q) What is ‘Alias’ ?

A) Alias is another name or alternate name. Alias can be give to table or column.

Syntax of Table Alias:
Select * from <TableName> <AliasName>
Example: 
Select * from Employee MyEmployees

Syntax of Column Alias: 
Select <Coloumn1> <Alias1>,<Column2 Alias2> from Employee
Example:
Select EmpName Name, Sal Salary from Emplyee

Part II of SQL Server Interview Questions