Change Name of an Existing Column in MySQL Table

Srinivas Gorla
Updated on 22-Jun-2020 13:01:19

277 Views

We can change the name of a particular existing column from a MySQL table by using CHANGE statement along with ALTER statement. Its syntax would be as follows −SyntaxALTER TABLE table_name CHANGE old_column_name new_column_name datatype;Here,  table_name is the name of the table from which we want to delete the column.Old_column_name is the name of the column which is to be changed.new_column_name is the name of the column which has to be given to the old column.ExampleIn this example, we are changing the name of the column ‘id’ to ‘studentid’ from table ‘student_info’ as follows −mysql> Select * from Student_info; +------+---------+------------+------------+ | id   | ... Read More

C# Program to Concatenate Two or More Lists

Chandu yadav
Updated on 22-Jun-2020 13:00:54

241 Views

Set three lists −// three lists var list1 = new List{3, 4}; var list2 = new List{1, 2, 3}; var list3 = new List{2, 5, 6};Now, use the Concat mthod to concat the above lists −var res1 = list1.Concat(list2); var res2 = res1.Concat(list3);Here is the complete code −Example Live Demousing System.Collections.Generic; using System.Linq; using System; public class Demo {    public static void Main() {       // three lists       var list1 = new List{3, 4};       var list2 = new List{1, 2, 3};       var list3 = new List{2, 5, 6};       // concat       var res1 = list1.Concat(list2);       var res2 = res1.Concat(list3);       foreach(int i in res2) {          Console.WriteLine(i);       }    } }Output3 4 1 2 3 2 5 6

Find Common Values from Two or More Lists in C#

George John
Updated on 22-Jun-2020 13:00:17

450 Views

Create more than one list −// two lists var list1 = new List{3, 4}; var list2 = new List{1, 2, 3};Now, use the Intersect() method to get the common values −var res = list1.Intersect(list2);The following is the complete code −Example Live Demousing System.Collections.Generic; using System.Linq; using System; public class Demo {    public static void Main() {       // two lists       var list1 = new List{3, 4};       var list2 = new List{1, 2, 3};       // common values       var res = list1.Intersect(list2);       foreach(int i in res) {          Console.WriteLine(i);       }    } }Output3

Handle Errors During Trigger Execution in MySQL

Kumar Varma
Updated on 22-Jun-2020 13:00:16

1K+ Views

Suppose if an error occurs during trigger execution then MySQL can handle it as follows −If a BEFORE trigger fails, the operation on the corresponding row is not performed.A BEFORE trigger is activated by the attempt to insert or modify the row, regardless of whether the attempt subsequently succeeds.An AFTER trigger is executed only if any BEFORE triggers and the row operation execute successfully.An error during either a BEFORE or AFTER trigger results in failure of the entire statement that caused trigger invocation.For transactional tables, failure of a statement should cause a rollback of all changes performed by the statement. ... Read More

Union Method in C#

Arjun Thakur
Updated on 22-Jun-2020 12:59:22

910 Views

The Union method gets the unique elements from both the lists.Let us set two lists −var list1 = new List{12, 65, 88, 45}; var list2 = new List{40, 34, 65};Now get the union of both the lists −var res = list1.Union(list2);The following is the example −Example Live Demousing System.Collections.Generic; using System.Linq; using System; public class Demo {    public static void Main() {       // two lists       var list1 = new List{12, 65, 88, 45};       var list2 = new List{40, 34, 65};       // finding union       var res = list1.Union(list2);       foreach(int i in res) {          Console.WriteLine(i);       }    } }Output12 65 88 45 40 34

Use Before Update Triggers to Emulate Check Constraint in Tables

Sai Subramanyam
Updated on 22-Jun-2020 12:59:22

92 Views

As we know that MySQL supports foreign key for referential integrity but it does not support CHECK constraint. But we can emulate them by using triggers. It can be illustrated with the help of an example given below −ExampleSuppose we have a table named ‘car’ which can have the fix syntax registration number like two letters, a dash, three digits, a dash, two letters as follows −mysql> Create table car (number char(9)); Query OK, 0 rows affected (0.32 sec)Creating BEFORE UPDATE trigger to emulate CHECK CONSTRAINT for updating the values −Now, suppose if we will try to update the table ... Read More

Intersect Method in C#

mkotla
Updated on 22-Jun-2020 12:58:45

515 Views

Use the Intesect method to get the common elements −Create lists −var list1 = new List{99, 87}; var list2 = new List{56, 87, 45, 99};Now, use the Intersect() method to get the common elements from the above list −list1.Intersect(list2);Here is the complete code −Example Live Demousing System.Collections.Generic; using System.Linq; using System; public class Demo {    public static void Main() {           // two lists       var list1 = new List{99, 87};       var list2 = new List{56, 87, 45, 99};       // common values       var res = list1.Intersect(list2);       foreach(int i in res) {          Console.WriteLine(i);       }    } }Output99 87

Understanding Database Views and MySQL Views

Swarali Sree
Updated on 22-Jun-2020 12:58:19

447 Views

A database view is nothing more than an SQL statement that is stored in the database with an associated name. A view is actually a composition of a table in the form of a predefined SQL query.A view can contain all rows of a table or select rows from a table. A MySQL view can be created from one or many tables which depend on the written MySQL query to create a view.Views, which are a type of virtual tables allow users to do the following −Structure data in a way that users or classes of users find natural or ... Read More

Print First Letter of Each Word in C#

usharani
Updated on 22-Jun-2020 12:58:16

1K+ Views

Let’s say the string is −string str = "Never Give Up!";Firstly, split each word −string[] strSplit = str.Split();Now, loop through each word and use the substring method to display the first letter as shown in the following code −Example Live Demousing System; public class Program {    public static void Main() {       string str = "Never Give Up!";       Console.WriteLine("Initial String= "+str);       Console.WriteLine("Displaying first letter of each word...");       string[] strSplit = str.Split();       foreach (string res in strSplit) {          Console.Write(res.Substring(0,1));       }    } }OutputInitial String= Never Give Up! Displaying first letter of each word... NGU

Print Number with Commas as 1000 Separators in C#

Giri Raju
Updated on 22-Jun-2020 12:57:50

2K+ Views

Firstly, set the number as string −string num = "1000000.8765";Now, work around differently for number before and after the decimal −string withoutDecimals = num.Substring(0, num.IndexOf(".")); string withDecimals = num.Substring(num.IndexOf("."));Use the ToString() method to set the format for 1000 separators −ToString("#,##0")The following is the complete code to display number with commas as 1000 separators −Example Live Demousing System; public class Program {    public static void Main() {       string num = "1000000.8765";       string withoutDecimals = num.Substring(0, num.IndexOf("."));       string withDecimals = num.Substring(num.IndexOf("."));       withoutDecimals = Convert.ToInt32(withoutDecimals).ToString("#,##0");       Console.WriteLine(withoutDecimals + withDecimals);    } }Output1,000,000.8765

Advertisements