A Little Noise

November 19, 2005

Concatenating NULL

Filed under: MySQL Gotchas — snoyes @ 4:00 am
CREATE TABLE myTable (
 id INT,
 string varchar(100) DEFAULT NULL
);
INSERT INTO myTable (id, string) VALUES (1, "First"), (2, NULL);
UPDATE myTable SET string = CONCAT(id, " has the value ", string);
SELECT * FROM myTable;

What is the output?
Show Answer ▼

November 18, 2005

Alias

Filed under: MySQL Gotchas — snoyes @ 4:00 am

What would result from the following?

CREATE TABLE my_table (
   id INT
);
INSERT INTO my_table (id) VALUES (2.9), (3), (3.4), (3.9), (4);
SELECT * FROM my_table AS m WHERE my_table.id > 3;

Show Answer ▼

November 17, 2005

Truncation

Filed under: MySQL Gotchas — snoyes @ 4:00 am

Assume the following has completed correctly:

CREATE TABLE test (
   charField varchar(5)
);

What is the end difference between the following two statements?

INSERT INTO test (charField) VALUES ("123456");
INSERT INTO test (charField) VALUES ("12345 ");

Show Answer ▼

November 16, 2005

Alias

Filed under: MySQL Gotchas — snoyes @ 4:47 pm

What would result from the following?

CREATE TABLE my_table (
id INT
);
INSERT INTO my_table (id) VALUES (2.9), (3), (3.4), (3.9), (4);
SELECT * FROM my_table AS m WHERE my_table.id > 3;

Show Answer ▼

Passwords

Filed under: MySQL Gotchas — snoyes @ 4:00 am

Assume the following have completed:

GRANT ALL ON test1.* TO 'johnQ'@'localhost' IDENTIFIED BY 'pass1';
GRANT ALL ON test2.* TO 'johnQ'@'localhost' IDENTIFIED BY 'pass2';

User johnQ has a query that joins tables from test1 to tables from test2. How should he log in?

a) Using ‘pass1’.
b) Using ‘pass2’.
c) Using ‘pass1’ and ‘pass2’, separated by a colon.
d) It can’t be done; he must change the two passwords to match.
e) Other (explain)
Show Answer ▼

November 15, 2005

Distinct Count

Filed under: MySQL Gotchas — snoyes @ 4:00 am
SELECT COUNT(DISTINCT someField) FROM someTable;
SELECT DISTINCT someField FROM someTable;

T/F: The value returned by the first will always equal the number of rows returned by the second.
Show Answer ▼

November 13, 2005

Unique Index

Filed under: MySQL Gotchas — snoyes @ 4:00 am

If I run the following, what will happen?

CREATE TABLE myTable (someField int, UNIQUE (someField));
INSERT INTO myTable VALUES (null);
INSERT INTO myTable VALUES (NULL);

Show Answer ▼

November 11, 2005

Truncation

Filed under: MySQL Gotchas — snoyes @ 4:47 pm

Assume the following has completed correctly:

CREATE TABLE test (
charField varchar(5)
);

What is the end difference between the following two statements?

INSERT INTO test (charField) VALUES ("123456");
INSERT INTO test (charField) VALUES ("12345 ");

Show Answer ▼

« Newer Posts

Powered by WordPress