Thursday, March 19, 2009

some sql server points

Question: what is cascade and restrict in drop table sql
Answerr:The CASCADE and RESTRICT keywords specify the action to be taken if other objects exist that are
dependent on the object being dropped. If CASCADE is specified, such objects will be dropped as well. If
RESTRICT is specified, an error is returned if other objects are affected, and no objects are dropped.
Question: How to import table using "INSERT" statement.
Answer : INSERT INTO new_table (Foo, Bar, Fizz, Buzz)SELECT Foo, Bar, Fizz, Buzz FROM source_table --
optionally WHERE ...
Question : what are DML,DDL,DCL,TCL Commands.
Answer:
DML is abbreviation of Data Manipulation Language. It is used to retrieve, store, modify, delete, insert and
update data in database.
Examples: SELECT, UPDATE, INSERT statements
DDL
DDL is abbreviation of Data Definition Language. It is used to create and modify the structure of database
objects in database.
Examples: CREATE, ALTER, DROP statements
DCL
DCL is abbreviation of Data Control Language. It is used to create roles, permissions, and referential
integrity as well it is used to control access to database by securing it.
Examples: GRANT, REVOKE statements
TCL
TCL is abbreviation of Transactional Control Language. It is used to manage different transactions occurring
within a database.
Examples: COMMIT, ROLLBACK statements
question: What is Ties in sql statement.
Answer:
TOP (expression) [PERCENT] [ WITH TIES ]
PERCENT Indicates that the query returns only the first expression percent of rows from the result set.
WITH TIES Specifies that additional rows be returned from the base result set with the same value in the ORDER BY columns
appearing as the last of the TOP n (PERCENT) rows. TOP...WITH TIES can be specified only in SELECT statements,
and only if an ORDER BY clause is specified.
The following example obtains the top 10 percent of all employees with the highest salary and returns them in
descending order according to salary base rate. Specifying WITH TIES makes sure that any employees that have
salaries equal to the lowest salary returned are also included in the result set, even if doing this exceeds 10
percent of employees.
Copy CodeUSE AdventureWorks;GOSELECT TOP(10) PERCENT WITH TIESc.FirstName, c.LastName, e.Title, e.Gender, r.RateFROM Person.Contact AS c INNER JOIN HumanResources.Employee AS e ON c.ContactID = e.ContactID INNER JOIN HumanResources.EmployeePayHistory AS r ON r.EmployeeID = e.EmployeeIDORDER BY Rate DESC;
Thanks
HELPONDESK TEAM

No comments: