ALLInterview.com :: Home Page KalAajKal.com
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
tip   To Refer this Site to Your Friends   Click Here
Google
 
Categories  >>  Software  >>  Databases  >>  SQL Server
 
 


 

 
 Oracle interview questions  Oracle Interview Questions
 SQL Server interview questions  SQL Server Interview Questions
 MS Access interview questions  MS Access Interview Questions
 MySQL interview questions  MySQL Interview Questions
 Postgre interview questions  Postgre Interview Questions
 Sybase interview questions  Sybase Interview Questions
 DB Architecture interview questions  DB Architecture Interview Questions
 DB Administration interview questions  DB Administration Interview Questions
 DB Development interview questions  DB Development Interview Questions
 SQL PLSQL interview questions  SQL PLSQL Interview Questions
 Databases AllOther interview questions  Databases AllOther Interview Questions
Question
What is the Query of getting last 10 transaction Reports
(like insert, update, Delete Data from Tabele) ?
 Question Submitted By :: Ganesh
I also faced this Question!!     Rank Answer Posted By  
 
  Re: What is the Query of getting last 10 transaction Reports (like insert, update, Delete Data from Tabele) ?
Answer
# 1
select top 10 (field list) from (tablename) order by (your
autonumbering/identity column) desc
 
Is This Answer Correct ?    4 Yes 16 No
Mona
 
  Re: What is the Query of getting last 10 transaction Reports (like insert, update, Delete Data from Tabele) ?
Answer
# 2
select top 10(fieds_name) from <table_name> order by 
(fields)name) desc.
 
Is This Answer Correct ?    1 Yes 12 No
Anand
 
 
 
  Re: What is the Query of getting last 10 transaction Reports (like insert, update, Delete Data from Tabele) ?
Answer
# 3
u hve to run query against transaction log.
 
Is This Answer Correct ?    1 Yes 0 No
Sanjeev Kumar
 
  Re: What is the Query of getting last 10 transaction Reports (like insert, update, Delete Data from Tabele) ?
Answer
# 4
CREATE TABLE Employee_Test
(
Emp_ID INT Identity,
Emp_name Varchar(100),
Emp_Sal Decimal (10,2)
)

INSERT INTO Employee_Test VALUES ('Anees',1000);
INSERT INTO Employee_Test VALUES ('Rick',1200);
INSERT INTO Employee_Test VALUES ('John',1100);
INSERT INTO Employee_Test VALUES ('Stephen',1300);
INSERT INTO Employee_Test VALUES ('Maria',1400);

drop table Employee_Test_Audit
CREATE TABLE Employee_Test_Audit
(
transid int NOT NULL IDENTITY (1,1) ,
Emp_ID int,
Emp_name varchar(100),
Emp_Sal decimal (10,2),
Audit_Action varchar(100),
Audit_Timestamp datetime
)

CREATE TRIGGER trgAfterInsert ON [dbo].[Employee_Test] 
FOR INSERT
AS
	declare @empid int;
	declare @empname varchar(100);
	declare @empsal decimal(10,2);
	declare @audit_action varchar(100);

	select @empid=i.Emp_ID from inserted i;	
	select @empname=i.Emp_Name from inserted i;	
	select @empsal=i.Emp_Sal from inserted i;	
	set @audit_action='Inserted Record -- After Insert Trigger.';

	insert into Employee_Test_Audit
          
(Emp_ID,Emp_Name,Emp_Sal,Audit_Action,Audit_Timestamp) 
	values(@empid,@empname,@empsal,@audit_action,getdate());

	PRINT 'AFTER INSERT trigger fired.'
GO

insert into Employee_Test values('Chris',1500);


CREATE TRIGGER trgAfterUpdate ON [dbo].[Employee_Test] 
FOR UPDATE
AS
	declare @empid int;
	declare @empname varchar(100);
	declare @empsal decimal(10,2);
	declare @audit_action varchar(100);

	select @empid=i.Emp_ID from inserted i;	
	select @empname=i.Emp_Name from inserted i;	
	select @empsal=i.Emp_Sal from inserted i;	
	
	if update(Emp_Name)
		set @audit_action='Updated Record -- After Update Trigger.';
	if update(Emp_Sal)
		set @audit_action='Updated Record -- After Update Trigger.';

	insert into
Employee_Test_Audit(Emp_ID,Emp_Name,Emp_Sal,Audit_Action,Audit_Timestamp)

	values(@empid,@empname,@empsal,@audit_action,getdate());

	PRINT 'AFTER UPDATE Trigger fired.'
GO



update Employee_Test set Emp_Sal=1550 where Emp_ID=6


CREATE TRIGGER trgAfterDelete ON [dbo].[Employee_Test] 
AFTER DELETE
AS
	declare @empid int;
	declare @empname varchar(100);
	declare @empsal decimal(10,2);
	declare @audit_action varchar(100);

	select @empid=d.Emp_ID from deleted d;	
	select @empname=d.Emp_Name from deleted d;	
	select @empsal=d.Emp_Sal from deleted d;	
	set @audit_action='Deleted -- After Delete Trigger.';

	insert into Employee_Test_Audit
(Emp_ID,Emp_Name,Emp_Sal,Audit_Action,Audit_Timestamp) 
	values(@empid,@empname,@empsal,@audit_action,getdate());

	PRINT 'AFTER DELETE TRIGGER fired.'
GO



CREATE TRIGGER trgInsteadOfDelete ON [dbo].[Employee_Test] 
INSTEAD OF DELETE
AS
	declare @emp_id int;
	declare @emp_name varchar(100);
	declare @emp_sal int;
	
	select @emp_id=d.Emp_ID from deleted d;
	select @emp_name=d.Emp_Name from deleted d;
	select @emp_sal=d.Emp_Sal from deleted d;

	BEGIN
		if(@emp_sal>1200)
		begin
			RAISERROR('Cannot delete where salary > 1200',16,1);
			ROLLBACK;
		end
		else
		begin
			delete from Employee_Test where Emp_ID=@emp_id;
			COMMIT;
			insert into
Employee_Test_Audit(Emp_ID,Emp_Name,Emp_Sal,Audit_Action,Audit_Timestamp)
			values(@emp_id,@emp_name,@emp_sal,'Deleted -- Instead Of
Delete Trigger.',getdate());
			PRINT 'Record Deleted -- Instead Of Delete Trigger.'
		end
	END
GO

delete from Employee_Test where Emp_ID=1

select * from Employee_Test

select * from Employee_Test_Audit

ALTER TABLE Employee_Test DISABLE TRIGGER trgAfterDelete

alter table  Employee_Test_Audit add column transid int NOT
NULL IDENTITY (1,1)

select top 10  * from  Employee_Test_Audit order by  transid
desc
 
Is This Answer Correct ?    3 Yes 2 No
Praveen Singh
 

 
 
 
Other SQL Server Interview Questions
 
  Question Asked @ Answers
 
Which is the subset of SQL commands used to manipulate Oracle Database structures, including tables?  2
A table contains list of customers and his city with other details. Each customer has a unique number and the table consists millions of data. Query is: I want to retrieve 10 customers from each city, no script, only from single query? Infosys3
What are the type of joins? When do we use Outer and Self joins?  3
What is WITH CHECK OPTION Karur-Vysya-Bank-KVB2
Why Do you want to work in this company? HCL3
What is a Join in SQL Server?  2
What is the use of DBCC commands?  1
How to find the date and time of last updated table? Teledata4
what is the diffrence between Snap Shot and Transaction Replication CSC1
How to Display, Amount of Disk Activity Generated by Transact-SQL Statements?  1
what is the difference between Delete and Truncate Geo-Research-Centre3
i want to create procedure for create table in sql server 2005 for example create procedure create_table @table varchar(20) as create @table( id int, name char(20) ) but it will get error what is solution? Aptech4
What is a view? is View updatable? IBM11
How to write stored procedure to update the data in 10 tables  4
What is the difference between HAVING clause and the WHERE clause?  4
Which command using Query Analyzer will give you the version of SQL server and operating system?  3
What is database replicaion? What are the different types of replication you can set up in SQL Server? HCL4
How to count the number of duplicate items in a table?  1
If you are working on a SQL database and if suddenly a developer changes the code and your queries results start giving errors,how will you check using a T-SQL query (on system tables) that what has changed in the database. Microsoft2
What are mdf,ndf,ldf files and how to see the data in those files? Accenture5
 
For more SQL Server Interview Questions Click Here 
 
 
 
 
 
   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us interview questions urls   External Links 
   
Copyright © 2007  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com