Interview Questions → SQL SERVER → SQL Server Questionnaire IV

SQL Server Questionnaire IV

















CREATE FUNCTION AddTwoNumbers
(
	@a int,
	@b int
)
RETURNS int
AS
BEGIN
	RETURN @a + @b
END
















CREATE FUNCTION GetEmployeeFromDepartment
( @department_id int )
RETURNS table
AS
RETURN (
SELECT EmployeeId, EmployeeName
FROM Employee
WHERE DepartmentId = @department_id
)
GO










customer_idcustomer_name
1Customer 1
2Customer 2


order_idorder_detailscustomer_id
1Order details11
2Order details22












BACKUP DATABASE [DB_NAME] TO DISK = [PATH]






CREATE SCHEMA [MySchema] AUTHORIZATION [dbo]




ALTER SCHEMA [MySchema] TRANSFER dbo.Employee






SELECT OBJECT_SCHEMA_NAME(T.[object_id],DB_ID()) AS [Schema],  
  T.[name] AS [table_name], I.[name] AS [index_name], AC.[name] AS [column_name],  
  I.[type_desc], I.[is_unique], I.[data_space_id], I.[ignore_dup_key], I.[is_primary_key], 
  I.[is_unique_constraint], I.[fill_factor],    I.[is_padded], I.[is_disabled], I.[is_hypothetical], 
  I.[allow_row_locks], I.[allow_page_locks], IC.[is_descending_key], IC.[is_included_column] 
FROM sys.[tables] AS T  
  INNER JOIN sys.[indexes] I ON T.[object_id] = I.[object_id]  
  INNER JOIN sys.[index_columns] IC ON I.[object_id] = IC.[object_id] 
  INNER JOIN sys.[all_columns] AC ON T.[object_id] = AC.[object_id] AND IC.[column_id] = AC.[column_id] 
WHERE T.[is_ms_shipped] = 0 AND I.[type_desc] <> 'HEAP' 
ORDER BY T.[name], I.[index_id], IC.[key_ordinal] 




UPDATE A 
SET A.Field1 = B.Field1 
FROM Table1 A, Table2 B 
WHERE A.Code = B.Code










Posted By  -  Karan Gupta


Query/Feedback


Your Email Id
 
Subject
 
Query/FeedbackCharacters remaining 250