Insert NULL Keyword in MySQL Character Column with NOT NULL Constraint

Kumar Varma
Updated on 19-Jun-2020 11:31:09

253 Views

It is quite possible to insert the NULL keyword as a value in a character type column having NOT NULL constraint because NULL is a value in itself. Following example will exhibit it −ExampleSuppose we have a table test2 having character type column ‘Name’ along with NOT NULL constraint on it. It can be checked from the DESCRIBE statement as follows −mysql> Describe test2\G *************************** 1. row ***************************   Field: id    Type: int(11)    Null: NO     Key: Default: NULL   Extra: *************************** 2. row ***************************   Field: NAME    Type: varchar(20)    Null: NO     Key: ... Read More

C# Program to Reverse an Array

karthikeya Boyini
Updated on 19-Jun-2020 11:30:41

3K+ Views

Firstly, set the original array −int[] arr = { 15, 16, 17, 18 }; // Original Array Console.WriteLine("Original Array= "); foreach (int i in arr) {    Console.WriteLine(i); }Now, use the Array.reverse() method to reverse the array −Array.Reverse(arr);ExampleThe following is the complete code to reverse an array in C#Live Demousing System; class Demo {    static void Main() {       int[] arr = { 15, 16, 17, 18 };       // Original Array       Console.WriteLine("Original Array= ");       foreach (int i in arr) {          Console.WriteLine(i);       }       // Reverse Array       Array.Reverse(arr);       Console.WriteLine("Reversed Array= ");       foreach (int j in arr) {          Console.WriteLine(j);       }       Console.ReadLine();    } }OutputOriginal Array=   15 16 17 18 Reversed Array=   18 17 16 15

C# Program to Reverse Words in a String

Samual Sam
Updated on 19-Jun-2020 11:29:21

3K+ Views

Let’s say the following is the string −Hello WorldAfter reversing the string, the words should be visible like −olleH dlroWExampleUse the reverse() method and try the following code to reverse words in a string.Live Demousing System; using System.Linq; class Demo {    static void Main() {       // original string       string str = "Hello World";       // reverse the string       string res = string.Join(" ", str.Split(' ').Select(s => new String(s.Reverse().ToArray())));       Console.WriteLine(res);    } }OutputolleH dlroW

Remove NOT NULL Constraint from MySQL Table Column

Lakshmi Srinivas
Updated on 19-Jun-2020 11:29:02

7K+ Views

We can remove a NOT NULL constraint from a column of an existing table by using the ALTER TABLE statement.ExampleSuppose we have a table ‘test123’ having a NOT NULL constraint on column ‘ID’ as follows −mysql> DESCRIBE test123; +-------+---------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra    | +-------+---------+------+-----+---------+-------+ | ID    | int(11) | NO   |     |   NULL  |       | | Date  | date    | YES  |     |   NULL  |       | +-------+---------+------+-----+---------+-------+ 2 rows in set (0.04 sec)Now if we ... Read More

C# Program to Find IP Address of the Client

karthikeya Boyini
Updated on 19-Jun-2020 11:28:29

2K+ Views

Firstly find the hostname using the Dns.GetHostName() method in C# −String hostName = string.Empty; hostName = Dns.GetHostName(); Console.WriteLine("Hostname: "+hostName);Now, use the IPHostEntry.AddressList Property to get IP Address −IPHostEntry myIP = Dns.GetHostEntry(hostName); IPAddress[] address = myIP.AddressList;ExampleTry the following code to display IP address −using System; using System.Net; class Program {    static void Main() {       String hostName = string.Empty;       hostName = Dns.GetHostName();       IPHostEntry myIP = Dns.GetHostEntry(hostName);       IPAddress[] address = myIP.AddressList;       for (int i = 0; i < address.Length; i++) {          Console.WriteLine("IP Address {1} : ",address[i].ToString());       }       Console.ReadLine();    } }

Apply NOT NULL Constraint to Existing MySQL Table Column

Jai Janardhan
Updated on 19-Jun-2020 11:27:51

429 Views

We can apply the NOT NULL constraint to a column of an existing MySQL table with the help of ALTER TABLE statement. SyntaxALTER TABLE table_name MODIFY colum_name datatype NOT NULL; Examplemysql> Create table test123(ID INT, Date DATE); Query OK, 0 rows affected (0.19 sec) mysql> Describe test123; +-------+---------+------+-----+---------+-------+ | Field | Type    | Null | Key | Default | Extra | +-------+---------+------+-----+---------+-------+ | ID    | int(11) | YES  |     | NULL    |       | | Date  | date    | YES  |     | NULL    |       | +-------+---------+------+-----+---------+-------+ ... Read More

Implement Sleep Method of Thread in C#

Samual Sam
Updated on 19-Jun-2020 11:27:24

398 Views

The sleep method of the thread is used to pause the thread for a specific period.If you want to set sleep for some seconds, then use it like the following code snippet −int sleepfor = 2000; Thread.Sleep(sleepfor);ExampleYou can try to run the following code to implement the sleep method of the thread.Live Demousing System; using System.Threading; namespace MyApplication {    class ThreadCreationProgram {       public static void CallToChildThread() {          Console.WriteLine("Child thread starts");          int sleepfor = 2000;          Console.WriteLine("Child Thread Paused for {0} seconds", sleepfor / 1000);   ... Read More

Chash Program to Illustrate Lower Triangular Matrix

karthikeya Boyini
Updated on 19-Jun-2020 11:26:45

280 Views

For the lower triangular matrix, set all the elements above the main diagonal to zero.Set the following condition −if (i >= j)    Console.Write(A[i, j] + "\t"); else    Console.Write("0\t");ExampleYou can try to run the following code to display a lower triangular matrix.Live Demousing System; using System.Linq; class Demo {    static void Main() {       int m, n, i, j;       Console.Write("Enter number of rows and columns of the matrix ");       m = Convert.ToInt16(Console.ReadLine());       n = Convert.ToInt16(Console.ReadLine());       int[, ] A = new int[10, 10];     ... Read More

NOT NULL Constraint with ALTER TABLE in SQL

karthikeya Boyini
Updated on 19-Jun-2020 11:26:11

266 Views

In this case, MySQL will return an error message regarding data truncated for the column. Following is an example of demonstrating it −ExampleSuppose we have a table ‘test2’ which contains a NULL value in column ‘ID’ at 2nd row. Now, if we will try to declare the column ID to NOT NULL then MySQL will return the error as follows −mysql> Select * from test2; +------+--------+ | ID   | Name   | +------+--------+ | 1    | Gaurav | | NULL | Rahul  | +------+--------+ 2 rows in set (0.00 sec) mysql> ALTER TABLE TEST2 MODIFY ID INT NOT NULL; ERROR 1265 (01000): Data truncated for column 'ID' at row 2

Count Vowels in a String using C#

Samual Sam
Updated on 19-Jun-2020 11:25:55

9K+ Views

You need to check for both the vowels and consonants, but do not forget to check for both the uppercase as well lowercase.For counting vowels, check for “aeiou” characters separately i.e.if (myStr[i] == 'a' || myStr[i] == 'e' || myStr[i] == 'i' || myStr[i] == 'o' || myStr[i] == 'u' || myStr[i] == 'A' || myStr[i] == 'E' || myStr[i] == 'I' || myStr[i] == 'O' || myStr[i] == 'U') {    vowel_count++; }ExampleThe following is the code to count the number of Vowels in a string.Live Demousing System; public class Demo {    public static void Main() {   ... Read More

Advertisements