1. SP may Return a value but Trigger Not,
2. In SP you can pass parameter But in trigger you can't
3. we explicitly call the Sp when Trigger are implicitly
fired
4. you can write a sp in Trigger but in a Trigger you cant
write SP.
5. Trigger written on an individual Table or View where SP
is written for an Database
you can get the details by clicking on ? on the dialog box that shows this error
or the flow is
Open the following
Tools > Options > Designers > Table and Database Designers > Prevent saving changes that require table re-creation. Just Turn this option off and you will be able to save the tables again.
and now you can save changes to all tables of any database.
Write following statement in Query Window
SELECT SERVERPROPERTY('productversion'), SERVERPROPERTY ('productlevel'), SERVERPROPERTY ('edition')
* The product version (10.0.1600.24)
* The product level (RTM)
* The edition (Enterprise)
Inorder to find out version of sql server write the following statements in query window
SELECT @@VERSION
using System.Data;
using System.Data.SqlClient;
using System.Windows.Forms;
namespace WindowsFormsApplication9
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
FillData();
}
void FillData()
{
// 1
// Open connection
using (SqlConnection c = new SqlConnection(
Properties.Settings.Default.DataConnectionString))
{
c.Open();
// 2
// Create new DataAdapter
using (SqlDataAdapter a = new SqlDataAdapter("SELECT * FROM EmployeeIDs", c))
{
// 3
// Use DataAdapter to fill DataTable
DataTable t = new DataTable();
a.Fill(t);
// 4
// Render data onto the screen
dataGridView1.DataSource = t; // <-- From your designer
}
}
}
}
}
Part 1. This creates a new SqlConnection instance. Note that you must include the System.Data.SqlClient namespace in your program. [See top of code]
Part 2. After calling Open() on the SqlConnection, we use another using block for the SqlDataAdapters. The using statements are ideal for disposing of resources, making your programs more efficient and reliable. [C# SqlClient Tutorial - dotnetperls.com]
Part 3. Here we instantiate and Fill a new DataTable. Note that the Fill method on DataTable will populate the internal rows and columns of the DataTable to match the SQL result.
Part 4. This part is commented out because it won't compile unless you have a DataGridView. We see the DataSource being assigned to the DataTable. The result will be a filled DataGridView with data from SQL Server.
Insert Trigger
CREATE TRIGGER trig_addAuthor ON [dbo].[Emp]
FOR INSERT
AS
DECLARE @newName VARCHAR(100)
SELECT @newName = (SELECT ename FROM Inserted)
-- Print the name of the new author
PRINT 'New author "' + @newName + '" added.'
Update Trigger
CREATE TRIGGER trig_updateemp
ON emp
FOR UPDATE
AS
DECLARE @oldName VARCHAR(100)
DECLARE @newName VARCHAR(100)
IF NOT UPDATE(ename)
BEGIN
RETURN
END
SELECT @oldName = (SELECT ename FROM Deleted)
SELECT @newName = (SELECT ename FROM Inserted)
PRINT 'Name changed from "' + @oldName + '" to "' + @newName + '"'