AND
, IN
, LIKE
, and between all belong to a category called what?BEGIN TRY SELECT 'Foo' AS Result; END TRY BEGIN CATCH SELECT 'Bar' AS Result; END CATCH
SELECT Students.first_name, Students.last_name, Departments.office_location FROM Students, Departments;
SELECT Students.first_name, Students.last_name, Departments.office_location FROM Students JOIN Departments ON Students.department = Departments.department;
SELECT Students.first_name, Students.last_name, Departments.office_location FROM Students JOIN Departments;
SELECT Students.first_name, Students.last_name, Departments.office_location FROM Students ON Students.department = Departments.department;
TRUNCATE TABLE
DELETE
MERGE
DROP
SELECT GameType, MaxPlayers, count(*) AS NumberOfGames FROM Games GROUP BY MaxPlayers, GameType ORDER BY MaxPlayers, GameType;
SELECT GameType, MaxPlayers, count(*) AS NumberOfGames FROM Games GROUP BY GameType, MaxPlayers ORDER BY GameType;
SELECT GameType, count(Players) AS MaxPlayers, NumberOfGames FROM Games GROUP BY GameType, MaxPlayers ORDER BY GameType;
SELECT GameType, MaxPlayers, count(*) AS NumberOfGames FROM Games GROUP BY GameType ORDER BY MaxPlayers;
DECLARE @UniqueID uniqueidentifier = NEWID();
SELECT @UniqueID AS Result;
WHERE team NOT 'Chemistry Cats';
WHERE team <> 'Chemistry Cats';
WHERE team != 'Chemistry Cats';
WHERE NOT team = 'Chemistry Cats';
WHERE
clause should you use to fill in the blank in this query?WHERE LastName = A*
WHERE LastName = LIKE '%A%'
WHERE LastName LIKE 'A%'
WHERE LastName IN ('A*')
SELECT LIMIT(2) first_name, department, team FROM Students ORDER BY points ASC;
SELECT TOP(2) first_name, deprtment, team FROM Students ORDER BY points DESC;
SELECT TOP(2) WITH TIES first_name, department, team FROM Students ORDER BY points;
SELECT BOTTOM(2) first_name, department, team FROM Students ORDER BY points ASC;
the picture of table is important here and there it can be seen that there are only two value with min points. Secondly, the previous answer was wrong because order by
DESC
will put highest points into the beginning of result list andTOP(2)
will take first two highest points, and we need the lowest points.
SELECT FLOOR(-1234.321)
UPDATE Students SET last_name = 'Smith' WHERE email = 'dfiggins@rouxacademy.com';
UPDATE Students SET last_name = 'Figgins' WHERE email = 'dfiggins@rouxacademy.com';
UPDATE Students SET last_name = 'Figgins' WHERE last_name = 'Smith' AND first-name = 'Donette';
UPDATE Students SET last_name = 'Smith' WHERE last_name = 'Figgins' AND first-name = 'Donette';
TRUNCATE FROM Products *;
DELETE FROM Products;
DELETE * FROM Products;
TRUNCATE TABLE Products;
SELECT 1 / 2 AS Result;
float
int
tinyint
bigint
SELECT 'abc\ def' AS Result;
SELECT TOP(1) first_name, last_name FROM Students ORDER BY NEWID();
SELECT TOP(1) RAND(first_name, last_name) FROM Student;
SELECT TOP(1) first_name, last_name FROM Student;
SELECT TOP(1) first_name, last_name FROM RAND(Student);
DECLARE @MyVariable int;
SET @MyVariable = 1;
GO
SELECT @MyVariable;
ALTER USER Sharon WITH DEFAULT_SCHEMA = Sales;
ALTER USER Sharon SET SCHEMA Sales;
CREATE SCHEMA Sales SET OWNER Sharon;
CREATE SCHEMA Sales AUTHORIZATION Sharon;
CROSS JOIN
between a table with 4 rows, and one with 5 rows, will give with _ rows.WHERE
clause should you use to fill in the blank in this query?SELECT ProductID, ProductName, SerialNumber FROM Products______ ;
WHERE SerialNumber LIKE '%10_3'
WHERE SerialNumber LIKE ('%10'+'_'+'3')
WHERE SerialNumber LIKE '%10"_"3'
WHERE SerialNumber LIKE '%10[_]3'
The underscore will match any single character, therefore you need to wrap the literal
_
with square brackets, otherwise, it may return a serial number ending with '1013', '10A3', etc.
FROM
clause is specified, what type of join is assumed?INNER
RIGHT
LEFT
FULL
RIGHT JOIN
ensure?Create table students(id int identity(1000,1), firstname varchar(20),
lastname varchar(30));
insert into students(firstname,lastname)values('mark','twain');
select * from students;
%OPTION% studentid firstname lastname 1 1001 mark twain
%OPTION% studentid firstname lastname 1 1 mark twain
%OPTION% studentid firstname lastname 1 1000 mark twain
%OPTION% studentid firstname lastname 1 null mark twain
CREATE TABLE Students ( StudentName varchar(50), Grade int );
SELECT StudentName FROM Students WHERE Grade = MAX(Grade);
SELECT TOP(1) StudentName FROM Students ORDER BY Grade;
SELECT TOP(1) WITH TIES StudentName FROM Students ORDER BY Grade DESC;
SELECT StudentName, MAX(Grade) FROM Students ORDER BY Grade DESC;
top(1)
with ties will take the highest grade and all other students with the same grade (because they are order by grade) and matches the highest grade.
select bookid, boooktitle, bookauthor,quantityonhand from inventory.books;
select * from dbo.books
heredbo
is a schema and the inventory is also schema. If we'd like to specify a database we should usedb_name.schema_name.table_name
INNER JOIN
between table1 and table2?TRUNCATE TABLE Students;
TRUNCATE * FROM Students;
DROP TABLE Students;
REMOVE * FROM Students;
CREATE TABLE
statement below. Which option, when placed in the blank space, ensures that the BookISBN column will not contain any duplicate values?CREATE TABLE Books ( BookID int PRIMARY KEY, BookISBN char(13) NOT NULL _____, BookTitle nvarchar(100) NOT NULL );
NO DUPLICATES
UNIQUE CONSTRAINT AK_Books_BookISBN
DUPLICATE CONSTRAINT (AK_Books_BookISBN)
CONSTRAINT AK_Books_BookISBN UNIQUE
CREATE TABLE Students ( StudentName varchar(50), Grade int );
SELECT StudentName
FROM Students
WHERE Grade = (SELECT MIN(Grade) FROM Student);
SELECT TOP(1) Grade FROM Students ORDER BY Grade;
SELECT MIN(Grade) FROM Students
SELECT MIN(Grade) FROM Students ORDER BY Grade;
Explanation: Column Students.Grade
is invalid in the ORDER BY
clause because it is not contained in either an aggregate function or the GROUP BY
clause.
SELECT MIN(Grade) FROM Students GROUP BY Grade;
Explanation: Grouping will return a list of all grades grouped by grade. The prompt wants just one returned row.
UPDATE Students SET last_name='Smith', email = 'dsmith@rouxacademy.com' WHERE id='56295';
UPDATE Students SET last_name='Smith' AND email = 'dsmith@rouxacademy.com' WHERE id='56295';
UPDATE Students SET last_name='Smith' AND email = 'dsmith@rouxacademy.com' WHERE id=56295;
UPDATE Students SET last_name='Smith', email = 'dsmith@rouxacademy.com' WHERE id=56295;
DECLARE @Counter int;
SET @Counter = 1;
WHILE @Counter > 0
BEGIN
SET @Counter = @Counter +1;
END;
UPDATES Students SET team = 'Philosophy Parrots' WHERE team = 'Philosophy Pandas';
UPDATES Students SET team =
Philosophy ParrotsWHERE team =
Philosophy Pandas;` UPDATES Students SET team = "Philosophy Parrots" WHERE team = "Philosophy Pandas";
UPDATES Students SET team = Philosophy Parrots WHERE team = Philosophy Pandas;
SELECT 123+'123' AS Result;
SELECT
statements, removing duplicates, which keyword can you use?CREATE TABLE MyTable (MyValue int); INSERT INTO MyTable VALUES (1); WHILE (SELECT MyValue FROM MyTable) < 5 BEGIN UPDATE My Table SET MyValue = MyValue + 1; END; SELECT MyValue AS Result FROM MyTable;
SELECT OrderID, SUM(LineTotal) AS SubTotal FROM Sales WHERE SUM(LineTotal) > 1000 GROUP BY OrderID ORDER BY OrderID;
WHERE
clause cannot be used with an aggregate function. GROUP BY
and ORDER BY
the same field. WHERE
clause should use the SubTotal
alias. CREATE TABLE Books ( BookID int PRIMARY KEY, BookTitle nvarchar(100) NOT NULL, PublisherID int NOT NULL ); CREATE TABLE Publishers ( PublisherID int PRIMARY KEY, PublisherName nvarchar(50) );
ALTER TABLE Books ADD CONSTRAINT FK Books_PublisherID FOREIGN KEY (PublisherID) REFERENCES Publishers (PublisherID) ON UPDATE SET NULL
ALTER TABLE Books ADD CONSTRAINT FK Books_PublisherID FOREIGN KEY (PublisherID) REFERENCES Publishers (PublisherID) ON DELETE CASCADE
ALTER TABLE Books ADD CONSTRAINT FK_Books_PublisherID FOREIGN KEY (PublisherID) REFERENCES Publishers (PublisherID)
ALTER TABLE Publishers ADD CONSTRAINT FK_Publishers_PublisherID FOREIGN KEY (PublisherID) REFERENCES Books (PublisherID) CASCADE DELETE
ALTER SCHEMA Products TRANSFER Warehouse.Inventory;
ALTER TABLE Warehouse.Inventory TRANSFER Products.Inventory;
ALTER TABLE Warehouse.Inventory ADD SCHEMA Products;
ALTER SCHEMA Warehouse ADD TABLE Inventory;
CREATE TABLE People ( PersonID int NOT NULL, PersonName nvarchar(50), _______ );
INDEX ON PersonID (PRIMARY KEY PK_People)
ADD NONCLUSTERED PRIMARY KEY CONSTRAINT PK_People ON PersonID
CONSTRAINT PK_People PRIMARY KEY NONCLUSTERED (PersonID)
PRIMARY KEY CONSTRAINT (PersonID) NONCLUSTERED INDEX
SELECT TOP(1) first_name, last_name FROM Students ORDER BY NEWID();
SELECT TOP(1) RAND(first_name, last_name) FROM Student;
SELECT TOP(1) first_name, last_name FROM Student;
SELECT TOP(1) first_name, last_name FROM RAND(Student);
Z:\Backups
directory. Which query should you use?BACKUP MyDatabase TO LOCATION = 'Z:\Backups\MyDatabase.bak';
CREATE BACKUP (DATABASE = 'MyDatabase' TO DISK = 'Z:\Backups\MyDatabase. bak');
BACKUP DATABASE MyDatabase ON 'Z:\Backups\MyDatabase.bak';
BACKUP DATABASE MyDatabase TO DISK = 'z:\Backups\MyDatabase.bak';
BEGIN TRAN myTransaction BEGIN LOG;
BEGIN TRAN myTransaction WITH LOG;
BEGIN TRAN myTransaction WITH MARK;
BEGIN TRAN WITH MARK myTransaction;
All statements must end with a semicolon.
All statements must operate on a table of data.
All statements must always be written in uppercase letters.
All statements must include more than one variable.
UPDATE Students SET last_name='Smith', email = 'dsmith@rouxacademy.com' WHERE id='56295';
UPDATE Students SET last_name='Smith', email = 'dsmith@rouxacademy.com' WHERE id=56295;
UPDATE Students SET last_name='Smith' AND email = 'dsmith@rouxacademy.com' WHERE id=56295;
UPDATE Students SET last_name='Smith' AND email = 'dsmith@rouxacademy.com' WHERE id='56295';
SELECT 123+'abc' AS Result;
Conversion failed when converting the varchar value 'abc' to data type int.
INSERT INTO Account (acct,bal) VALUES ('12345', 100); UPDATE Account SET bal=bal+100; BEGIN; UPDATE Account SET bal=bal+100. ROLLBACK; SELECT bal FROM Account WHERE acct='12345'; );
You will get an error because ROLLBACK deletes the row that was update
SELECT first_name, email FROM Students WHERE department = Humanities;
SELECT first_name, email FROM Students WHERE department = "Humanities";
SELECT first_name, email FROM Students WHERE department = 'Humanities';
SELECT 'first_name', 'email' FROM 'Students' WHERE 'department' = "Humanities";
DROP TABLE Products.Inventory;
USE Products; DROP TABLE Inventory;
USE Products; DELETE Inventory;
USE Products.Inventory; DROP TABLE Inventory;
This statement first switches to the Products database using the
USE
command and then drops the Inventory table using theDROP TABLE
command.
SELECT 123+'123' AS Result;
CREATE TABLE MyNumbers (
MyDecimalColumn decimal(5,2) NOT NULL
);
INSERT INTO MyNumbers VALUES (123), (45);
SELECT * FROM MyNumbers;
DROP TABLE Products.Inventory;
USE Products; DROP TABLE Inventory;
USE Products; DELETE Inventory;
USE Products.Inventory; DROP TABLE Inventory;