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
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
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
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
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
Foreach in C++C++ 11 introduced foreach loop to traverse over each element. Here is an example −Example Live Demo#include using namespace std; int main() { int myArr[] = { 99, 15, 67 }; // foreach loop for (int ele : myArr) cout
As we know that views are definitions built on the top of other tables or views and stored in the database. Followings are benefits of using MySQL views as compared to selecting data directly from MySQL base tablesSimplify data accessThe use of views simplifies the data access because of the following reasons −A view can be used to perform a calculation and display its result. For example, a view definition that invokes aggregate functions can be used to display a summary.With the help of views, we can select a restricted set of rows by means of an appropriate WHERE clause ... Read More
Firstly, set the list −List myList = new List () { 5, 10, 7 };Now, set the value of a variable to 1 that would help us in multiplying −int prod = 1;Loop through and get the product −foreach(int i in myList) { prod = prod*i; }The following is the code −Example Live Demousing System; using System.Collections.Generic; public class Program { public static void Main() { List myList = new List() { 5, 10, 7 }; Console.WriteLine("List: "); foreach(int i in myList) { Console.WriteLine(i); } int prod = 1; foreach(int i in myList) { prod = prod*i; } Console.WriteLine("Product: {0}",prod); } }OutputList: 5 10 7 Product: 350
MySQL VersionAs we know that MySQL 5 introduced views, hence, first of all, we need to check for the version of MySQL before starting writing and using stored procedures. It can be done with the following query −mysql> Select VERSION(); +-----------+ | VERSION() | +-----------+ | 5.7.20 | +-----------+ 1 row in set (0.10 sec)Privileges for current userActually CREATE VIEW statement requires the CREATE VIEW privilege. Privileges for the current user can be checked with the following query −mysql> SHOW PRIVILEGESSelecting a databaseBefore creating a view we must have to select a database from the available databases. It can ... Read More
To check for all vowels, firstly set the condition to check −string res = str.Where(chk =< "aeiouAEIOU".Contains(chk)).Distinct();Above, we have used the string −string str = "the quick brown fox jumps over the lazy dog";Now, using the Any() method checks whether the string has any vowels or not −if(!res.Any()) Console.WriteLine("No vowels!");Loop through the string to get the vowels −Example Live Demousing System; using System.Linq; public class Program { public static void Main() { string str = "the quick brown fox jumps over the lazy dog"; var res = str.Where(chk =< "aeiouAEIOU".Contains(chk)).Distinct(); ... Read More
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP