Create Table Tab2 with Same Attributes as Table Tab1

Mandalika
Updated on 12-Sep-2020 14:13:49

293 Views

DB2 gives us an option to copy the structure of an existing table to a new table. To copy the attributes and column of table TAB1 to a new table TAB2 we can use the following command−CREATE TABLE DBSET1.TAB2    LIKE DBSET1.TAB1The CREATE TABLE reserved words are followed by table name. The table name needs to be qualified by a database in which it will reside. In this case this new table is TAB2 and its database is DBSET1.The LIKE parameter is used after that followed by the name of the original table qualified by its database i.e. DBSET1.TAB1The important ... Read More

Create View on Table for Column Name, Age, and Enrollment ID

Mandalika
Updated on 12-Sep-2020 13:20:28

328 Views

A view is an alternative way of representing the data stored in a table. A view can be used to increase the performance of the query since the view contains very limited rows as compared to its source table. We can use the below command to create a view on an existing table TAB1.CREATE VIEW AGEVIEW (NAME, AGE, ENROLLMENT_ID)    AS SELECT NAME, AGE, ENROLLMENT_ID FROM TAB1       WHERE AGE > 10;We have to use CREATE VIEW reserved words in order to create a new view. This will be followed by the name of the view (AGEVIEW).The columns ... Read More

Foreign Key Referencing of Two DB2 Tables

Mandalika
Updated on 12-Sep-2020 13:18:09

618 Views

A foreign key is a column in a table that establishes a referential link with another table. A foreign key can be defined during creation of table (CREATE TABLE command) or it can be defined by modifying the table (ALTER TABLE command). However, before defining any key as foreign key, make sure that an index is built up on that column. We can use the below command to define an existing column CLASS in table TAB1 as a foriegn key which links to table TAB2.ALTER TABLE TAB1 ADD FOREIGN KEY (CLASS) REFERENCES CLASSDATA (CLASS_ID);The ALTER TABLE reserved words are followed ... Read More

Retrieve Specific ID Records from a List in JavaScript

AmitDiwan
Updated on 12-Sep-2020 09:01:44

251 Views

Let’s say the following is our list −var details=[    {id:101, name:"John", age:21},    {id:111, name:"David", age:24},    {id:1, name:"Mike", age:22},    {id:"", name:"Sam", age:20},    {id: 1, name:"Carol", age:23},    {id:null, name:"Robert", age:25},    {id:1, name:"Adam", age:24},    {id:"", name:"Chris", age:23} ];You can use the concept of filter to retrieve values based on specific ID.Examplevar details=[    {id:101, name:"John", age:21},    {id:111, name:"David", age:24},    {id:1, name:"Mike", age:22},    {id:"", name:"Sam", age:20},    {id: 1, name:"Carol", age:23},    {id:null, name:"Robert", age:25},    {id:1, name:"Adam", age:24},    {id:"", name:"Chris", age:23} ]; var getIdWithValue1 = details.filter(obj => obj.id === 1); console.log(getIdWithValue1);To ... Read More

Convert List of String Coordinates to Float Lists of Latitude and Longitude in JavaScript

AmitDiwan
Updated on 12-Sep-2020 09:00:14

608 Views

Let’s say the following are our coordinates −var listOfStrings = ["10.45322, -6.8766363", "78.93664664, -9.74646646", "7888.7664664, -10.64664632"];To convert the above into two float lists of Latitude and Longitude, use split() on the basis of comma(, ) along with map().Examplevar listOfStrings = ["10.45322, -6.8766363", "78.93664664, -9.74646646", "7888.7664664, -10.64664632"]; var latitude = []; var longitude = []; listOfStrings.forEach(obj => obj.split(', ') .map(Number) .forEach((value, index) => [latitude, longitude][index].push(value)) ); console.log("All positive value is latitude=") console.log(latitude); console.log("All negative value is longitude=") console.log(longitude);To run the above program, you need to use the following command −node fileName.js.Here, my file name is demo180.js.OutputThis will produce the following output ... Read More

Fetch Values by Ignoring a Specific One in JavaScript

AmitDiwan
Updated on 12-Sep-2020 08:57:41

394 Views

To ignore a specific value, use the logical Not (!) operator in if condition and fetch watching you want to include.Examplevar customerDetails=[    {       customerName:"John",       customerAge:28,       customerCountryName:"US"    },    {       customerName:"David",       customerAge:25,       customerCountryName:"AUS"    },    {       customerName:"Mike",       customerAge:32,       customerCountryName:"UK"    } ] for(var i=0;i node demo179.js The country name is=US The country name is=UK

Select Random Values from an Array in JavaScript

AmitDiwan
Updated on 12-Sep-2020 08:56:31

557 Views

To select random values from an array, use the concept of Math.random().Examplevar subjectNames = ["Javascript", "MySQL", "Java", "MongoDB", "Python","Spring Framework"]; for(var index = subjectNames.length - 1; index > 0; index--){    var rndIndex = Math.floor(Math.random() * (index + 1));    var subjNameTemp = subjectNames[rndIndex];    subjectNames[rndIndex] = subjectNames[index];    subjectNames[index] = subjNameTemp; } var getRandomSubjectName = subjectNames.slice(0, 3); console.log(getRandomSubjectName);To run the above program, you need to use the following command −node fileName.js.Here, my file name is demo178.js.OutputThis will produce the following output −PS C:\Users\Amit\javascript-code> node demo178.js [ 'Javascript', 'MySQL', 'Python' ]

Get Only Specific Values in an Array of Objects in JavaScript

AmitDiwan
Updated on 12-Sep-2020 08:55:15

13K+ Views

Let’s say the following is our array of objects −var details = [{    studentName: "John",    studentMarks: 92 }, {    studentName: "David",    studentMarks: 89 }, {    studentName: "Mike",    studentMarks: 98 }, ];To get only specific values in an array of objects in JavaScript, use the concept of filter().Examplevar details = [{    studentName: "John",    studentMarks: 92 }, {    studentName: "David",    studentMarks: 89 }, {    studentName: "Mike",    studentMarks: 98 }, ]; var specificValuesFromArray = details.filter(obj => obj.studentMarks === 92 || obj.studentMarks === 98); console.log(specificValuesFromArray)To run the above program, you need to ... Read More

Add New Object to JavaScript Array After Map with Condition

AmitDiwan
Updated on 12-Sep-2020 08:54:09

437 Views

For this, you can use filter() along with map().Exampleconst details =[    { customerName: 'John', customerCountryName: 'UK', isMarried :true },    { customerName: 'David', customerCountryName: 'AUS', isMarried :false },    { customerName: 'Mike', customerCountryName: 'US', isMarried :false } ] let tempObject = details.filter(obj=> obj.isMarried == true); tempObject["customerNameWithIsMarriedFalse"] = details.filter(obj => obj.isMarried== false).map(obj => obj.customerName); console.log(tempObject);To run the above program, you need to use the following command −node fileName.js.Here, my file name is demo176.js.OutputThis will produce the following output −PS C:\Users\Amit\javascript-code> node demo176.js [    { customerName: 'John', customerCountryName: 'UK', isMarried: true }, customerNameWithIsMarriedFalse: [ 'David', 'Mike' ] ]

Increment Value by 10 on Button Click in JavaScript

AmitDiwan
Updated on 12-Sep-2020 08:52:28

1K+ Views

For this, use click() along with parseInt().Example Live Demo Document 10 addValue10EachTimePressMe    addValue = 0;    $("#addSequenceOf10").click(function() {       var actualValue = parseInt($("#add").html());       addValue =addValue+ actualValue;       $("#sequenceValue").html(addValue);    }); To run the above program, just save the file name anyName.html(index.html) and right click on the file and select the option open with live server in VS Code editor.OutputThis will produce the following output −Now, press the button you will get 10 then 20 30 40…….N; as in the below output −After clicking one more time, the snapshot is as follows.This will produce the following output −

Advertisements