Friday, February 24, 2012
how to store a record before deleting it using triggers
im new to SQL. i wanted to save a particular record before deleting it usin
g a delete trigger can anyone help me on this .. thnxIO you want to store the whole row and therefore the data you could
consider leaving the data in the table and marking the row as "deleted"
by flagging the row with a bit column as deleted. If you don=B4t want to
maintain the whole row you could do something like this:
CREATE Trigger DELTrg_SomeTable ON SomeTable
FOR DELETE
AS
BEGIN
INSERT INTO SOmeTable
SELECT * from Deleted
/*
Rather than using the asterix to Select the column and data I would
namer the columns you want to select and insert therefore lgiving you
the opputunity to fill in additional fields which are extended int he
archive (something like an audit data, who deleted what row from what
host, etc.)
*/
END
HTH, Jens Suessmeyer.
How to store a content into database
Hi everyone,
I'm just using TEXTBOX control to save data into my DB. My question is, if I have multiple lines of sentences, it does not store as what it looks like. For example;
Hello,
Mike
It stores into the database as "Hello, Mike" and if I read from the database, it does not have seperate lines and shows it like this;
Hello, Mike
How can I store the contents into database and make the contents as original?
(Sorry for the poor English, but I hope you understand it.)
One way of doing this will be to replace all new lines with <BR> before saving it to database.
do something like that:
TextBox1.Text.Replace(vbCrLf,
"<br>")|||SQL Server dose accept carriage returns, but note it stores carriage returns as 2 characters:1st for line feed (ascii code 10)and 2nd for carriage return (ascii code 13). How did you push the lines in the textbox into database? If you use a single string which contains multiple lines, then you can get the lines back from database. For example:
using (SqlConnection conn = new SqlConnection(@."Data Source=.\iori2000;Integrated Security=SSPI;Database=tempdb"))
{
conn.Open();
SqlCommand cmd = new SqlCommand("CustOrderHist", conn);
string s1 = textBox1.Text;
cmd.CommandText = "INSERT INTO testString SELECT @.v";
cmd.Parameters.Add("@.v", SqlDbType.VarChar).Value = s1;
cmd.ExecuteNonQuery();
cmd.CommandText = "SELECT s FROM testString";
SqlDataReader sda = cmd.ExecuteReader();
sda.Read();
s1 = sda.GetString(0);
textBox1.Text = "Retrieved:\n" + s1;
}