Sie sind auf Seite 1von 5

What is the difference between char and varchar data types?

The char is a fixed-length character data type, the varchar is a variable-length


character data type.
You can use char when the data entries in a column are expected to be the same size.
You can use varchar when the data entries in a column are expected to vary
considerably in size.
What is the difference between UNION and UNION ALL Sql syntax?
UNION - is used to select information from two tables, it selects only distinct records
UNION ALL - selects all the records from both the tables.
How can you raise custom errors from stored procedure?
The RAISERROR statement is used to produce the error message or retrieve a
custom message that is stored in the sysmessages table.
The Syntax is follows

RAISERROR ({msg_id|msg_str}{, severity, state}


[argument [,…n]])
[WITH option [, …n]]
Custom error messages must have identifier numbers greater than or equal to 50000,
and the message itself is limited to 255 characters or less. As an example, to create a
new error message, assign it an identifier number of 55555, and assign it a severity
code of 10, you would call sp_addmessage like this:
sp_addmessage 55555, 10, 'New error message.'
You could then raise that new error in a procedure like this:
RAISERROR 55555, 10

 The @@ERROR function only indicates the error number that occurred in the last
T-SQL statement that was executed.
 If @@ERROR returns zero, then no error occurred.
What is the difference between clustered and nonclustered indexes?
A clustered index is a special type of index that reorders the way records in the table
are physically stored. Therefore table can have only one clustered index. The leaf
nodes of a clustered index contain the data pages.

A nonclustered index is a special type of index in which the logical order of the index
does not match the physical stored order of the rows on disk. The leaf nodes of a non
clustered index contain index rows. A table can have 249 non clustered indexes
What is the difference between PRIMARY KEY and UNIQUE constraints?
Primary Key Unique Key
1.It Wont allow Null values. 1.It allows only one Null value
2.Primary key will create clustered 2.Unique key will create non-clustered
index by default. index by default.
3.Only one Primary Key constraints can 3.Any number of Unique Key constraints
be added to a table can be added to a table.
What is Database Normalization?
Its a process of efficiently organizing data in a database
There are two goals of the normalization process:
1.eliminate redundant data (for example, storing the same data in more than one table)
and
2.ensure data dependencies make sense (only storing related data in a table).
Both of these are worthy goals as they reduce the amount of space a database
consumes and ensure that data is logically stored. There are five normalizaion forms,
Which are..
First normal form (1NF)
Eliminate duplicative columns from the same table. Create separate tables for each
group of related data and identify each row with a unique column or set of columns
(the primary key).
Second normal form (2NF)
Remove subsets of data that apply to multiple rows of a table and place them in
separate tables. Create relationships between these new tables and their predecessors
through the use of foreign keys.
Third normal form (3NF)
Remove columns that are not dependent upon the primary key.
fourth normal form (4NF)
A relation is in 4NF if it has no multi-valued dependencies.
Fifth normal form is very rarely seen
What is transaction?
Transactions group a set of tasks into a single execution unit. Each transaction begins
with a specific task and ends when all the tasks in the group successfully complete. If
any of the tasks fails, the transaction fails. Therefore, a transaction has only two
results: success or failure. Incomplete steps result in the failure of the transaction.
Users can group two or more Transact-SQL statements into a single transaction using
the following statements:
---Begin Transaction
---Rollback Transaction
---Commit Transaction
If anything goes wrong with any of the grouped statements, all changes need to be
aborted. The process of reversing changes is called rollback in SQL Server
terminology. If everything is in order with all statements within a single transaction,
all changes are recorded together in the database. In SQL Server terminology, we say
that these changes are committed to the database.
Delete Vs Truncate
Truncate Delete
1.Removes all rows from a table 1.Removes rows one at a time and records an
without logging the individual row entry in the transaction log for each deleted
deletes. row
2.Cannot apply where conditions. 2.Can apply where conditions
3.Auto commit & can't rollback. 3.no Auto Commit & can rollback.
4.Truncated table's table space can be 4.table space cannt be reused immediatly
reused immediatly
eg TRUNCATE TABLE authors eg A. Use DELETE with no parameters
This example deletes all rows from the authors
table.
USE pubs
DELETE authors
B. Use DELETE on a set of rows
Because au_lname may not be unique, this
example deletes all rows in which au_lname is
McBadden.
USE pubs
DELETE FROM authors WHERE au_lname =
'McBadden'
User Defined Functions vs Stored Procedures
User Defined Functions Stored Procedures
1.Executable from SQL SELECT and
1.Use EXECUTE or EXEC to run
SQL action queries
2.Doesn't return output parameters 2.Supports output parameters
3.Can create a physical table and populate it,
3.Returns table variable
but can't return a table variable
4.Can join to a UDF 4.Can't join to a stored procedure
5.Can't make a permanent changes to 5.Stored Procedures can be used to change
the server environment or an external some of the server environment and operation
source environment
6.Can't be used in an XML FOR
6.Can be used in an XML FOR clause
Clause
7.Errors are ignored and T-SQL processes the
7.T-SQL errors stop the function
next statement. You must include error
when an error occurs
handling code.
8.Use CREATE FUNCTION to
8.Use CREATE PROCEDURE to create
create
What is the use of set NoCount ON in stored procedures?
Use the SET NOCOUNT ON statement to prevent SQL Server from sending the
DONE_IN_PROC message for each statement in a stored procedure. For example, if
you have eight operations in a stored procedure and you have not used this option
eight messages are returned to the caller. Each message contains the number of
affected rows for the respective statement.
12
what are the types of triggers in Sql server 2000?
There are two different types of triggers in Microsoft SQL Server 2000. They are
INSTEAD OF triggers and AFTER triggers. Like stored procedures and views,
triggers can also be encrypted.
An AFTER trigger is a trigger that gets executed automatically before the transaction
is committed or rolled back.
An AFTER trigger can be created only on tables, not on views

A trigger which gets executed automatically in place of triggering actions i.e.,


INSERT, DELETE and UPDATE is called an INSTEAD OF trigger.
INSTEAD OF triggers can be created on views
A view or table can have only one INSTEAD OF trigger for each INSERT,
UPDATE and DELETE events.
what are the types of triggers in Oracle vs Sql server 2000?
Oracle 9i SQL Server 2000
BEFORE triggers,
AFTER triggers, AFTER triggers,
Triggers
INSTEAD OF triggers, INSTEAD OF triggers
Database Event triggers
What is a cursor in SQLServer?
A cursor is a database object that applications use to manipulate data by rows instead
of recordsets. You can use cursors to perform multiple operations in a row-by-row
manner, against the resultset. You can do this with or without returning to the original
table. In other words, cursors conceptually return a resultset based on tables within a
database.

You can use the cursors to do the following:

1. Allow positioning at specific rows of the resultset.


2. Retrieve a single row, or set of rows, from the current positions in the resultset.
3. Support data modifications to the rows at the current position in the resultset.
4. Support different levels of visibility to changes that others users make to the
database data that is presented in the resultset.
5. Provide T-SQL statements in scripts, stored procedures, and triggers, to access the
data in the resultset.
Ref can view at here
Write a SQL Query to find 4th maximum?
Select * From Employee E1 Where (4-1) = (Select Count(Distinct(E2.Salary)) From
Employee E2 Where E2.Salary > E1.Salary)
what are types of joins?
INNER JOIN - will display records only exist in both the tables
LEFT OUTER JOIN - will display all the records in the left table of the SQL query
RIGHT OUTER JOIN - will display all the records of the right table of the SQL
query
FULL OUTER JOIN - All rows in all joined tables and queries are included,
whether they match or not.
What are diff types constraints in sqlserver?
Constraints: Rules defined on the table which cannot be violated by the users.
Constraints are used to enforce the data integrity. This ensures the accuracy and
reliability of the data in the database. The following categories of the data integrity
exist:

Entity Integrity (PRIMERY KEY , UNIQUE) - ensures that there are no duplicate
rows in a table.
Domain Integrity (CHECK, NOT NULL) - enforces valid entries for a given
column by restricting the type, the format, or the range of possible values.
Referential integrity (FORIEGN KEY) - ensures that rows cannot be deleted,
which are used by other records (for example, corresponding data values between
tables will be vital).
User-Defined Integrity enforces some specific business rules that do not fall into
entity, domain, or referential integrity categories.
What are three SQL keywords used to change or set someone’s permissions?
Grant, Deny and Revoke
12

Das könnte Ihnen auch gefallen