General Method of Writing Triggers
Types of Triggers
- After Triggers
- Instead Of Triggers
DECLARE @FIRST DATETIME
DECLARE @SECOND DATETIME
SET @FIRST = GETDATE()
-- Execute your stored procedure here. i.e exec name of your SP
EXEC STORED PROCEDURE
SET @SECOND = GETDATE()
SELECT DATEDIFF(SECOND,@FIRST,@SECOND) AS TOTAL_TIME
SET STATISTICS TIME ON
-- Execute your stored procedure here. i.e exec name of your SP
EXEC STORED PROCEDURE
SET STATISTICS TIME OFF
DECLARE @T DATETIME
SET @T = CURRENT_TIMESTAMP
-- Execute your stored procedure here. i.e exec name of your SP
EXEC STORED PROCEDURE
SELECT DATEDIFF(SECOND,@T,CURRENT_TIMESTAMP) AS TOTAL_TIME
DECLARE @T DATETIME
SET @T = CURRENT_TIMESTAMP
-- Execute your stored procedure here. i.e exec name of your SP
EXEC STORED PROCEDURE
SELECT DATEDIFF(MILLISECOND,@T,CURRENT_TIMESTAMP) AS TOTAL_TIME
In this tutorial we will learn about local and global temporary tables in MicroSoft Sql Server. Temporary table are very handy when you need to process data or perform calculation using same selection. They are also very useful when you need data temporarily because when client session disconnet they vanishes away. There are two type of temporary tables and below are the details of each type.
-- First Highest Value
select max(orderid) as HighestValue from orders
-- Second Highest Value
select max(orderid) as SecondHighestValue from orders where orderid not in (select max(orderid) as HighestValue from orders)
-- Second Highest Value
SELECT orderid as SecondHighestValue FROM orders WHERE orderid =( SELECT MAX(orderid) FROM orders WHERE orderid<(SELECT max(orderid) FROM orders))
As a database learner or In your first database lab class you may be asked to create database and tables in SQL Server. Here I am going to tell you the method of creating your first database and table in SQL Server.
Open your SQL Server Management Studio(SSMS) and Press ctrl + n to open new query window. Type below query in your query window and execute it to create your first database.
create database <your_database_name>
create database DEMODB
To create your first table in above mentioned database "DEMODB" first you need to select the database you created with above sql query. After that you can make table with the help of create table command.
use <database_name>
create table <your_table_name>
(
your_column_name1 data_type,
your_column_name2 data_type,
your_column_name2 data_type
)
create table customer
(
customer_id bigint,
customer_name varchar(100),
customer_dob datetime
)
Today when I tried to connect my application(which is in visual studio 2010) with SQL server 2005 as a database. I've got the following error in my application due to which I was unable to proceed further.
Often you have seen this "Could not load file or assembly" kind of error and In my case, it was "‘Microsoft.SqlServer.Management.Sdk.Sfc, Version=X.x.x.x,(In my case it was 10.0.0.0 version) Culture=neutral, PublicKeyToken=89845dcd8080cc91′ or one of its dependencies. The system cannot find the file specified." error and it is due to some of the missing file i.e. possibly dll or any other file
After a bit of researching, I've got the solution that is a pretty simple one because we just need to install three files, and boom it will work. You can download these files from the Microsoft website.
After installing the above three files try to connect your application with the SQL server database and if still, you get the same error message then don't worry and close your application then start it again and you will be able to connect it.
Here are the related links from where I got the solution to this problem and I thought to share it.
http://chiragrdarji.wordpress.com/2009/05/14/could-not-load-file-or-assembly-microsoft-sqlserver-management-sdk-sfc/
http://technologyteams.blogspot.com/2010/05/unable-to-add-data-connection-could-not.html
Hope this post will help you in solving your problem.
Today we will learn about the SQL alter statements and look into scenarios in which we can use them and how.So here we go
CREATE TABLE [dbo].[person](
[PERSON_ID] [varchar](20) NOT NULL,
[PERSON_NAME] [varchar](15) NULL,
[PERSON_ADDRESS] [varchar](20) NULL,
[Department] [varchar](20) NULL
)
1. -- To change table name
sp_rename 'person_table','person'
2. -- To change column name
sp_rename 'person.designation','Department','column'
To alter tables use
the following queries:
3. -- To Add a column
alter table person
add Designation varchar(20)
4. -- To Drop a column
alter table person
drop column designation
5. -- To change data type of column
alter table person
alter column person_id int
6. -- To Add primary key constraint
alter table person
add constraint pk_person_id primary
key(person_id)
7. -- To Drop primary key constraint
alter table person
drop constraint pk_person_id
8. -- To Add foreign key constraint
alter table person
add constraint fk_person_id foreign
key(person_id) references department(person_id)
9. -- To Drop foreign key constraint
alter table person
drop constraint fk_person_id