Saraswat World

VIEW in SQL

WHAT IS A VIEW IN SQL?

SQL

A VIEW in SQL is a virtual table showing up-to-date result-set of SQL statements.Unlike a real table, a view does not exist in the database as astored set of data values. Instead, the rows and columns of data visible through the view arethe query results produced by the query that defines the view. HOW TO CREATE VIEW […]

CHECK in SQL

HOW TO USE CHECK CONSTRAINT IN SQL?

SQL

The CHECK constraint in SQL is used to limit the value that can be placed in a column or table. Example of CHECK constraint in SQL server- CREATE TABLE Students (ID INT NOT NULL, FirstName VARCHAR(200),Fees INT CHECK (Fees>0)); Naming of CHECK constraint in SQL server during creation of table- CREATE TABLE Students (ID INT NOT NULL, FirstName VARCHAR(200), Fees INT , Age INT , CONSTRAINT chk CHECK (Fees>0 AND Age>21));  […]

NOT NULL in SQL

HOW TO USE NOT NULL CONSTRAINT IN SQL?

SQL

The NOT NULL constraint in SQL is used to disallow the acceptance of NULL value in a column(s). A column, by default, can hold NULL values. Example of NOT NULL constraint in SQL server- CREATE TABLE Students (   ID INT NOT NULL,   FirstName VARCHAR(200) NOT NULL,   Age INT); NOT NULL constraint creation on existing table- ALTER TABLE Students ALTER COLUMN Age INT […]

UNIQUE in SQL

HOW TO USE UNIQUE CONSTRAINT IN SQL?

SQL

The UNIQUE constraint in SQL is used to ensure that all values in a column are unique or different. Example of UNIQUE constraint in SQL server- CREATE TABLE Students (ID INT NOT NULL UNIQUE, FirstName VARCHAR(200),Fees INT); Naming of UNIQUE constraint in SQL server during creation of table- CREATE TABLE Students (ID INT NOT NULL, FirstName VARCHAR(200) NOT NULL, Fees INT , Age INT , CONSTRAINT unk UNIQUE (ID, FirstName));  โ€“constraint named as unk […]

ALIASES in SQL

WHAT ARE SQL ALIASES?

SQL

The aliases in SQL are used to give temporary name to a table or a column in a table. An alias is created with the AS keyword. Syntax of alias in SQL for the column- SELECT <column_name1> AS <alias_name1>, โ€ฆ.     <column_nameN> AS <alias_nameN> FROM <table_name>; Syntax of alias in SQL for table- SELECT<column_name(s)> FROM <table_name> AS <alias_name>; Example of alias in SQL for column- SELECT CustomerName AS Customer, PostalCode AS [Postal Code] […]

DEFAULT in SQL

HOW TO USE DEFAULT CONSTRAINT IN SQL?

SQL

The DEFAULT constraint in SQL is used to set a default value for a column. Example of DEFAULT constraint creation in SQL server- CREATE TABLE Students ( ID INT NOT NULL UNIQUE, FirstName VARCHAR(200), Fees INT, City VARCHAR(200) DEFAULT โ€˜Delhiโ€™ ); Example to create DEFAULT constraint on existing table in SQL server- ALTER TABLE Students ADD  CONSTRAINT d_city DEFAULT โ€˜Delhiโ€™ FOR City; Example to DROP a UNIQUE constraint in SQL server โ€“ […]

CREATE INDEX in SQL

HOW TO CREATE INDEX IN SQL?

SQL

Theย CREATE INDEXย statement in SQL is used to create indexes in tables. Indexes are used for faster retrieval of records which speed up queries. Syntax of CREATE INDEX in SQL server. It allow duplicate values CREATE INDEX <index_name> ON <table_name> (column_name1..column_nameN); Syntax of CREATE UNIQUE INDEX in SQL server. It donโ€™t allow duplicate values CREATE UNIQUE INDEX <index_name> ON <table_name> (column_name1..column_nameN); Example of […]

UNION in SQL

HOW TO USE UNION IN SQL?

SQL

UNIONย operator is used to select distinct values from the combination of the result-set of two or more SELECT statements, provided that the data type and the number of fields, and the order of fields must be the same for every SELECT statement. To allow duplicate values in the result set, useย UNION ALL. Syntax of UNION […]

WHAT IS WINDOW FUNCTION IN SQL SERVER?

WHAT IS WINDOW FUNCTION IN SQL SERVER?

SQL

Window function is a function which uses values from one or multiple rows to return a value for each row. The term Window describes the set of rows in the database on which the function will operate using an OVER() clause. The main advantage of using Window functions over regular aggregate functions is- Window functions […]

WHAT IS CTE OR COMMON TABLE EXPRESSION IN SQL SERVER?

WHAT IS CTE OR COMMON TABLE EXPRESSION IN SQL SERVER?

SQL

CTE or Common Table Expression, is a named temporary result set that we can define and reference within the execution scope of single SELECT, INSERT, UPDATE, DELETE, MERGE or CREATE VIEW statement.A CTE is similar to a view, but it is defined within the execution of a single statement and lasts only for the duration […]

WHAT IS PIVOT AND UNPIVOT IN SQL SERVER?

WHAT IS PIVOT AND UNPIVOT IN SQL SERVER?

SQL

PIVOT and UNPIVOT are relational operators. PIVOT rotates a table-valued expression by turning the unique values from one column in the expression into multiple columns in the output. And PIVOT runs aggregations where theyโ€™re required on any remaining column values that are wanted in the final output. UNPIVOT carries out the opposite operation to PIVOT […]

Explain a situation where finally block will not be executed in Java?

Explain a situation where finally block will not be executed in Java?

JAVA INTERVIEW QUESTIONS

A situation where finally block will not be executed in Java- Finally block will not be executed whenever jvm shutdowns. If we use system.exit(0) in try statementfinally block if present will not be executed.

Explain the importance of finally over return statement in Java?

Explain the importance of finally over return statement in Java?

JAVA INTERVIEW QUESTIONS

Importance of finally over return statement in Java- finally block is more important than return statement when both are present in a program. For example, if there is any return statement present inside try or catch block , and finally block is also present firstfinally statement will be executed and then return statement will be […]

Explain importance of throws keyword in java?

Explain importance of throws keyword in java?

JAVA INTERVIEW QUESTIONS

Throws statement is used at the end of method signature to indicate that an exception of a given typemay be thrown from the method.The main purpose of throws keyword is to delegate responsibility of exception handling to the callermethods, in the case of checked exception.In the case of unchecked exceptions, it is not required to […]

Can we write any code after throw statement in Java?

Can we write any code after throw statement in Java?

JAVA INTERVIEW QUESTIONS

After throw statement jvm stop execution and subsequent statements are not executed. If we try to write any statement after throw we do get compile time error saying unreachable code.

Explain throw keyword in java?

Explain throw keyword in java?

JAVA INTERVIEW QUESTIONS

Generally JVM throws the exception and we handle the exceptions by using try catch block. But there aresituations where we have to throw userdefined exceptions or runtime exceptions. In such case we usethrow keyword to throw exception explicitly.Syntax : throw throwableInstance;Throwable instance must be of type throwable or any of its subclasses.After the throw statement […]

What is default Exception handling in java?

What is default Exception handling in java?

JAVA INTERVIEW QUESTIONS

When JVM detects exception causing code, it constructs a new exception handling object by including thefollowing information. 1) Name of Exception2) Description about the Exception3) Location of Exception. After creation of object by JVM it checks whether there is exception handling code or not. If there isexception handling code then exception handles and continues the […]

Differences between checked and Unchecked exceptions in java?

Differences between checked and Unchecked exceptions in java?

JAVA INTERVIEW QUESTIONS

Unchecked Exception Checked Exception All the subclasses of RuntimeException are called unchecked exception. All subclasses of Throwable class except RuntimeException are called as checked exceptions Unchecked exceptions need not be handled at compile time as These exceptions arise mostly due to coding mistakes in our program. Checked Exceptions need to be handled at compiletime. Here, […]

What are unchecked exceptions in java?

What are unchecked exceptions in java?

JAVA INTERVIEW QUESTIONS

Unchecked exceptions in javaAll subclasses of RuntimeException are called unchecked exceptions. These are unchecked exceptionsbecause compiler does not checks if a method handles or throws exceptions.Program compiles even if we do not catch the exception or throws the exception.If an exception occurs in the program, program terminates . It is difficult to handle these exceptionsbecause […]

What are checked Exceptions in Java?

What are checked Exceptions in Java?

JAVA INTERVIEW QUESTIONS

Checked Exceptions in Java1) All the subclasses of Throwable class except error, Runtime Exception and its subclasses are checkedexceptions.2) Checked exception should be thrown with keyword throws or should be provided try catch block, elsethe program would not compile. We do get compilation error.Examples :1) IOException,2) SQlException,3) FileNotFoundException,4) InvocationTargetException,5) CloneNotSupportedException6) ClassNotFoundException7) InstantiationException