AND
, IN
, LIKE
e tra tutte appartengono a una categoria chiamata cosa?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
dovresti utilizzare per riempire il vuoto in questa 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;
L'immagine della tabella è importante qui e può essere visto che ci sono solo due valori con punteggi minimi. In secondo luogo, la risposta precedente era sbagliata perché l'ordine per
DESC
metterà i punteggi più alti all'inizio della lista dei risultati eTOP(2)
prenderà i primi due punteggi più alti, e noi abbiamo bisogno dei punteggi più bassi.
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
tra una tabella con 4 righe e una con 5 righe darà _ righe.WHERE
dovresti utilizzare per riempire il vuoto in questa 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'
L'underscore corrisponderà a qualsiasi singolo carattere, quindi è necessario avvolgere il trattino basso letterale con parentesi quadre, altrimenti potrebbe restituire un numero di serie che termina con '1013', '10A3', ecc.
FROM
di una query è specificato, quale tipo di join viene considerato?INNER
RIGHT
LEFT
FULL
RIGHT JOIN
?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 prenderà il voto più alto e tutti gli altri studenti con lo stesso voto (perché sono ordinati per voto) e corrispondono al voto più alto.
select bookid, boooktitle, bookauthor,quantityonhand from inventory.books;
select * from dbo.books
quidbo
è uno schema e l'inventario è anche uno schema. Se volessimo specificare un
database dovremmo usare db_name.schema_name.table_name
INNER JOIN
tra table1 e table2?TRUNCATE TABLE Students;
TRUNCATE * FROM Students;
DROP TABLE Students;
REMOVE * FROM Students;
CREATE TABLE
qui sotto. Qual è l'opzione che, inserita nello spazio vuoto, garantisce che la colonna BookISBN non conterrà valori duplicati?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;
Spiegazione: La colonna Students.Grade
non è valida nella clausola ORDER BY
perché non è contenuta né in una funzione di aggregazione né nella clausola GROUP BY
.
SELECT MIN(Grade) FROM Students GROUP BY Grade;
Spiegazione: Il raggruppamento restituirà una lista di tutti i voti raggruppati per voto. Il prompt vuole solo una riga restituita.
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;
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'; );
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
del server. Quale query dovresti utilizzare?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';
myTransaction
venga registrato nel log delle transazioni. Quale istruzione rappresenta il modo migliore per raggiungere questo obiettivo?BEGIN TRAN myTransaction BEGIN LOG;
BEGIN TRAN myTransaction WITH LOG;
BEGIN TRAN myTransaction WITH MARK;
BEGIN TRAN WITH MARK myTransaction;
Tutte le istruzioni devono terminare con un punto e virgola.
Tutte le istruzioni devono operare su una tabella di dati.
Tutte le istruzioni devono sempre essere scritte in lettere maiuscole.
Tutte le istruzioni devono includere più di una variabile.
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;
xacademy.com' WHERE id='56295';`
SELECT 123+'abc' AS Result;
Conversion failed when converting the varchar value 'abc' to data type int.
CREATE TABLE MyNumbers (
MyDecimalColumn decimal(5,2) NOT NULL
);
INSERT INTO MyNumbers VALUES (123), (45);
SELECT * FROM MyNumbers;
SELECT 123+'123' AS Result;
SELECT 123+'abc' AS Result;
Conversion failed when converting the varchar value 'abc' to data type int.
SELECT 123+'123' AS Result;
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'; );
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;
Questa istruzione prima passa al database Products usando il comando
USE
e quindi elimina la tabella Inventory usando il comandoDROP TABLE
.
DECLARE @Counter int;
SET @Counter = 1;
WHILE @Counter > 0
BEGIN
SET @Counter = @Counter +1;
END;
SELECT 123+'123' 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);
DROP TABLE Products.Inventory;
USE Products; DROP TABLE Inventory;
USE Products; DELETE Inventory;
USE Products.Inventory; DROP TABLE Inventory;