Sunday, 2 February 2020

MySQL Multiple Choice Question

1. Which of the following is not one of the top databases in use today?
(a) Amazon CloudIt
(b) Microsoft SQL Server
(c) Oracle
(d) MySQL
(e) MongoDB
Solution:
A (Amazon CloudIt)

Explanation : Microsoft SQL server, Oracle, and MySQL are relational databases. MongoDB is non relational databases. Amazon CloudIt is not a database.
2. MySQL is free to use as a back-end database for a website.
(a) True
(b) False

Solution:
 True

  Explanation : MySQL is free to use as a back-end database for a website.

3. MySQL uses which TCP/IP port by default?
Solution:
MySQL uses 3306 TCP/IP port by default.

4. MySQL is primarily a relational database based on SQL.
(a) True
(b) False
Solution:
True

Explanation : MySQL is primarily a relational database based on Structured Query Language (SQL).

5. Which of the following is correct about this command: mysql -u root -p?
(a) Installs MySQL for the first time
(b) Starts the MySQL Service in Linux
(c) Starts the MySQL Service in Windows
(d) Configures MySQL to like rootbeer
(e) Connects to MySQL on localhost
Solution:
E) Connects to MySQL on localhost

Explanation : 'mysql -u root -p' command is used to connect to MySQL on localhost. To connect to remote host we have to use -h option. 'mysql -h <remote-ip> -u <user> -p
6. The MySQL Configuration file for Windows is:
(a) my.cnf
(b) mysql.prop
(c) my.ini
(d) my.conf
(e) mysql.conf
Solution:
c (my.ini)
7. The MySQL Configuration file for Linux is:
(a) my.cnf
(b) mysql.prop
(c) my.ini
(d) my.conf
(e) mysql.conf
Solution:
a (my.cnf)

Explanation : we can define most of MySQL's configuration parameters in the my.cnf file which is located in /etc/mysql folder.

Sunday, 26 January 2020

How to monitor changes to an SQL server table

How can I monitor an SQL Server database for changes to a table without using triggers or modifying the structure of the database in any way? My preferred programming environment is .NET and C#.

I'd like to be able to support any SQL Server 2000 SP4 or newer. My application is a bolt-on data visualization for another company's product. Our customer base is in the thousands, so I don't want to have to put in requirements that we modify the third-party vendor's table at every installation.

By "changes to a table" I mean changes to table data, not changes to table structure.

Ultimately, I would like the change to trigger an event in my application, instead of having to check for changes at an interval.

The best course of action given my requirements (no triggers or schema modification, SQL Server 2000 and 2005) seems to be to use the BINARY_CHECKSUM function in T-SQL. The way I plan to implement is this:

Every X seconds run the following query:

SELECT CHECKSUM_AGG(BINARY_CHECKSUM(*))
FROM sample_table
WITH (NOLOCK);
And compare that against the stored value. If the value has changed, go through the table row by row using the query:
SELECT row_id, BINARY_CHECKSUM(*)
FROM sample_table
WITH (NOLOCK);
And compare the returned checksums against stored values.

Solution:
CHECKSUM command:
 SELECT CHECKSUM_AGG(BINARY_CHECKSUM(*)) FROM sample_table WITH (NOLOCK);
That will return the same number each time it's run as long as the table contents haven't changed.

Tuesday, 31 December 2019

How do I store binary data in MySQL?

Q: How do I store binary data in MySQL?

Solution:

The basic answer is in a BLOB data type / attribute domain. BLOB is short for Binary Large Object and that column data type is specific for handling binary data.

you should be aware that there are other binary data formats:
TINYBLOB/BLOB/MEDIUMBLOB/LONGBLOB
VARBINARY
BINARY
Each has their use cases. If it is a known (short) length (e.g. packed data) often times BINARY or VARBINARY will work. They have the added benefit of being able ton index on them.


For a table like this:
CREATE TABLE binary_data (
    id INT(4) NOT NULL AUTO_INCREMENT PRIMARY KEY,
    description CHAR(50),
    bin_data LONGBLOB,
    filename CHAR(50),
    filesize CHAR(50),
    filetype CHAR(50)
);

Monday, 23 December 2019

Quick book payment integration

I am attempting to incorporate quick book to send and receive payments. But I can't locate api for payment (To send and receive payments to others). Furthermore, I am unable to locate api  to get bank transactions linked with quick book. Client has quick book software but want to fetch transaction in other software.

Solution:

Quick Book does not support any APIs to send and receive payments to others. This is not something that Quick Book / Intuit Payments supports.

Saturday, 7 December 2019

The average monthly precipitation (in.) for Boston and Seattle during 2012 are given in the vectors below

Q: The average monthly precipitation (in.) for Boston and Seattle during 2012 are given in the vectors below (data from the U.S. National Oceanic and Atmospheric Administration) BOS = [2.67 1.00 1.21 3.09 3.43 4.71 3.88 3.08 4.10 2.62 1.01 5.93] SEA = [6.83 3.63 7.20 2.68 2.05 2.96 1.04 0.00 0.03 6.71 8.28 6.85] Where the elements in the vectors are in the order of the months (January, February, etc.) Write your program to answer the following: (a) Calculate the total precipitation for the year and monthly average precipitation in each city. Do NOT use MATLAB's built-in functions sum and mean. (b) How many months was the precipitation above the average in each city? (c) How many months, and on which months, was the precipitation in Boston lower than the precipitation in Seattle? 

Solution:

 
clear all;
close all;
bos=[2.67,1,1.21,3.09,3.43,4.71,3.88,3.08,4.10,2.62,1.01,5.93];
sea=[6.83,3.63,7.20,2.68,2.05,2.96,1.04,0,0.03,6.71,8.28,6.85];
tot_bos=0;
tot_sea=0;
for x=1:1:12
tot_bos=tot_bos+bos(x);
tot_sea=tot_sea+sea(x);
end
avg_bos=tot_bos/12;
avg_sea=tot_sea/12;
above_avg_bos=0;
above_avg_sea=0;
for y=1:1:12
if(bos(y)>avg_bos)
above_avg_bos=1+above_avg_bos
end;
if(sea(y)>avg_sea)
above_avg_sea=1+above_avg_sea
end;
end
i=1;
for z=1:1:12
if(bos(z)<sea(z));
a(i)=z;
i=i+1;
end
end
fprintf('Total participation for the year in BOS ans SEA are %0.2d %0.2d\n',tot_bos,tot_sea);
fprintf('Monthly avg participation for the year in BOS ans SEA are %0.2d %d\n',avg_bos,avg_sea);
fprintf('Totoal month of above avg participation in the year for BOS and SEA %i %i\n',above_avg_bos,above_avg_sea);
fprintf('Total month where BOS is less than SEA %i and months are %i',i-1,a);

The average monthly precipitation (in.) for Boston and Seattle during 2012 are given in the vectors below

Q: The average monthly precipitation (in.) for Boston and Seattle during 2012 are given in the vectors below (data from the U.S. National Oceanic and Atmospheric Administration). BOS = [2.67 1.00 1.21 3.09 3.43 4.71 3.88 3.08 4.10 2.62 1.01 5.93] SEA = [6.83 3.63 7.20 2.68 2.05 2.96 1.04 0.00 0.03 6.71 8.28 6.85] where the elements in the vectors are in the order of the months (January, February, etc.) Write a program to answer the following: Calculate the total precipitation for the year and monthly average precipitation in each city. How many months was the precipitation above the average in each city? (c) How many months, and on which months, was the precipitation in Boston lower than the precipitation in Seattle?

Solution:

 
bos = [2.67 1.00 1.21 3.09 3.43 4.71 3.88 3.08 4.10 2.62 1.01 5.93];
sea = [6.83 3.63 7.20 2.68 2.05 2.96 1.04 0.00 0.03 6.71 8.28 6.85];
fprintf('Total precipitation in Boston=%f \n',sum(bos));
fprintf('Total precipitation in Seattle=%f \n',sum(sea));
fprintf('Average monthly precipitation in Boston=%f \n',sum(bos)/12);
fprintf('Average monthly precipitation in Seattle=%f \n',sum(sea)/12);
numMonthBos=0;
for v=bos
if v > sum(bos)/12
numMonthBos+=1;
end
end
numMonthSea=0;
for v=bos
if v > sum(sea)/12
numMonthSea+=1;
end
end
fprintf('Number of months when precipitation is above average in Boston=%d \n',numMonthBos);
fprintf('Number of months when precipitation is above average in Seattle=%d \n',numMonthSea);
total1=0;
for i=1:12
if bos(i) < sea(i)
total1+=1;
end
end
fprintf('Number of months when precipitation is lower in boston than in Seattle=%d \n',total1);

sh-4.3$ octave -qf --no-window-system demo.m octave: X11 DISPLAY environment variable not set octave: disabling warning: func

Write a program that will collect numbers from the user until the user enters a non-numeric value.

Q:
MATLAB Help:
Write a program that will collect numbers from the user until the user enters a non-numeric value. It then returns the sum and the average of all the numbers entered. Example below:
-----
Enter a number: 2.5
Enter a Number: 2
Enter a Number: 59
Enter a Number: 2
Enter a Number: 9
Enter a Number: 1.1
Enter a Number: k
The sum of the 6 numbers entered is 75.6. The average is 12.6.

Solution:

result = 0;
count = 0;
while(1)
val = input("Enter a number: ",'s')
val = str2double(val)
if(val == NaN)
break;
else
result = result + val;
end
count = count + 1;
end
fprintf("The sum of the %d numbers entered is %f. The average is %f.\n",count,result, (result/count));