Drop Existing Column from a MySQL Table

Abhinanda Shri
Updated on 22-Jun-2020 12:46:11

283 Views

We can delete a particular existing column from a MySQL table by using the DROP statement along with an ALTER statement. Its syntax would be as follows −SyntaxALTER TABLE table_name DROP column_name;Here,  table_name is the name of the table from which we want to delete the column.Column_name is the name of the column which is to be deleted from the table.ExampleIn this example, we are deleting the column ‘address’ from table ‘student_detail’ as follows −mysql> select * from student_detail; +-----------+-------------+----------+ | Studentid | StudentName | address  | +-----------+-------------+----------+ |       100 | Gaurav      | Delhi   ... Read More

Check the Existence of a File Using C#

Chandu yadav
Updated on 22-Jun-2020 12:45:42

142 Views

Let’s say we need to find the following file −E:ew.txtTo check the existence of the above file, use the Exists() method −if (File.Exists(@"E:ew.txt")) {    Console.WriteLine("File exists..."); }Here is the complete code to check the existence of a file −Example Live Demousing System; using System.IO; public class Demo {    public static void Main() {       if (File.Exists(@"E:ew.txt")) {          Console.WriteLine("File exists...");       } else {          Console.WriteLine("File does not exist in the E directory!");       }    } }OutputFile does not exist in the E directory!

C# Truncate Method

George John
Updated on 22-Jun-2020 12:45:15

434 Views

Use the Truncate method in C# to remove all the numbers after decimal places.Let’s say the following is our number −20.35MTo remove the numbers after decimal places, use Truncate() −decimal.Truncate(20.35M)Let us see the comple code −Exampleusing System; using System.Linq; class Demo {    static void Main() {       decimal dc = 20.35M;       Console.WriteLine(dc.Truncate(val));    } }

Get Metadata of MySQL Events

Ankith Reddy
Updated on 22-Jun-2020 12:45:07

270 Views

It can be done with the help of the INFORMATION_SCHEMA database. The following statement will give us the metadata of events −mysql> SELECT * from INFORMATION_SCHEMA.EVENTS WHERE EVENT_NAME LIKE '%event%' A ND EVENT_SCHEMA = 'query'\G *************************** 1. row ***************************       EVENT_CATALOG: def        EVENT_SCHEMA: query          EVENT_NAME: testing_event6             DEFINER: root@localhost           TIME_ZONE: SYSTEM          EVENT_BODY: SQL    EVENT_DEFINITION: INSERT INTO event_message(message, generated_at) values('EVENT ALTERED', NOW())          EVENT_TYPE: ONE TIME          EXECUTE_AT: 2017-11-22 20:03:52 ... Read More

C# HashTable ToEven Property

Ankith Reddy
Updated on 22-Jun-2020 12:44:49

123 Views

The ToEven property is used with the MidpointRounding Enumeration to round a number to the nearest even number.Declare and initialize a decimal number −decimal val = 70.45M;To rounde a number to the nearest even number −decimal.Round(val, 0, MidpointRounding.ToEven)Here is the complete code −Example Live Demousing System; using System.Linq; class Demo {    static void Main() {       decimal val = 70.45M;       Console.WriteLine(decimal.Round(val, 0, MidpointRounding.ToEven));    } }Output70

Open a Plain Text File in C#

Arjun Thakur
Updated on 22-Jun-2020 12:44:26

327 Views

To open a plain text file, use the StreamReader class. The following opens a file for reading −StreamReader sr = new StreamReader("d:/new.txt")Now, display the content of the file −while ((line = sr.ReadLine()) != null) {    Console.WriteLine(line); }Here is the code −Example Live Demousing System; using System.IO; namespace FileApplication {    class Program {       static void Main(string[] args) {          try {             using (StreamReader sr = new StreamReader("d:/new.txt")) {                string line;                // ... Read More

Different Ways of Reading a File in C#

Chandu yadav
Updated on 22-Jun-2020 12:43:05

303 Views

Here, we are reading two different files −Reading text file −Example Live Demousing System; using System.IO; namespace FileApplication {    class Program {       static void Main(string[] args) {          try {             using (StreamReader sr = new StreamReader("d:/new.txt")) {                string line;                // Read and display lines from the file until                // the end of the file is reached.                while ((line ... Read More

Create MySQL Recurring Event with Specified Time Period

Arushi
Updated on 22-Jun-2020 12:40:27

384 Views

As we know that recurring event means that it will be executed after regular time of interval and expires at the specified time. To illustrate the creation of such kind of events we are using the following example in which we are creating an event which will execute after every minute and expires after one hour −mysql> CREATE EVENT testing_event10 ON SCHEDULE EVERY 1 MINUTE STARTS CURRENT_TIMESTAMP ENDS CURRENT_TIMESTAMP + INTERVAL 1 HOUR DO INSERT INTO event_message(message, generated_at) Values('Recrring evnts', NOW()); Query OK, 0 rows affected (0.00 sec) mysql> Select * from event_message; +----+----------------+---------------------+ | ID | MESSAGE   ... Read More

Open Hidden File Using C#

George John
Updated on 22-Jun-2020 12:40:11

728 Views

To open a hidden file, first make it visible. You can do this by removing the hidden attribute set on it −FileInfo file= new FileInfo(Environment.CurrentDirectory + @"\myFile.txt"); file.Attributes &= ~FileAttributes.Hidden;Now treat it as a normal text file and open it. Read the content −using (StreamReader sr = new StreamReader("myFile.txt")) {    string line;    while ((line = sr.ReadLine()) != null) {       Console.WriteLine(line);    } }After reading, set the attribute as hidden again to hide the file −file.Attributes |= FileAttributes.Hidden;

Fetch Alternate Odd Numbered Records from MySQL Table

Rishi Rathor
Updated on 22-Jun-2020 12:39:47

1K+ Views

To understand this concept, we are using the data from table ‘Information’ as follows −mysql> Select * from Information; +----+---------+ | id | Name    | +----+---------+ | 1  | Gaurav  | | 2  | Ram     | | 3  | Rahul   | | 4  | Aarav   | | 5  | Aryan   | | 6  | Krishan | +----+---------+ 6 rows in set (0.00 sec)Now, the query below will fetch the alternate odd-numbered records from the above table ‘Information’ −mysql> Select id,Name from information group by id having mod(id,2) = 1; +----+--------+ | id | Name   | +----+--------+ | 1  | Gaurav | | 3  | Rahul  | | 5  | Aryan  | +----+--------+ 3 rows in set (0.09 sec)

Advertisements