AND
, IN
, LIKE
, y BETWEEN
pertenecen a una categoría llamada qué?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
deberías usar para llenar el espacio en blanco en esta consulta?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;
La imagen de la tabla es importante aquí y se puede ver que solo hay dos valores con puntos mínimos. En segundo lugar, la respuesta anterior era incorrecta porque el orden por
DESC
pondrá los puntos más altos al principio de la lista de resultados yTOP(2)
tomará los dos puntos más altos, y necesitamos los puntos más bajos.
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;
manera más eficiente la edad de una persona en años?
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
entre una tabla con 4 filas y una con 5 filas dará como resultado _ filas.WHERE
deberías usar para llenar el espacio en blanco en esta consulta?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'
El guion bajo coincidirá con cualquier carácter único, por lo tanto, es necesario envolver el guion bajo literal
_
con corchetes cuadrados, de lo contrario, podría devolver un número de serie que termine con '1013', '10A3', etc.
FROM
de una consulta, ¿qué tipo de unión se asume?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)
conWITH TIES
tomará la calificación más alta y todos los demás estudiantes con la misma calificación (porque están ordenados por calificación) y coinciden con la calificación más alta.
select bookid, boooktitle, bookauthor,quantityonhand from inventory.books;
select * from dbo.books
aquídbo
es un esquema y inventory también es un esquema. Si quisiéramos especificar una base de datos deberíamos usarnombre_bd.nombre_esquema.nombre_tabla
INNER JOIN
entre tabla1 y tabla2?] Se muestran todos los registros de tabla1, independientemente de si los registros tienen una fila correspondiente en tabla2
TRUNCATE TABLE Students;
TRUNCATE * FROM Students;
DROP TABLE Students;
REMOVE * FROM Students;
CREATE TABLE
a continuación. ¿Qué opción, cuando se coloca en el espacio en blanco, garantiza que la columna BookISBN no contendrá valores duplicados?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;
Explicación: La columna Students.Grade
es inválida en la cláusula ORDER BY
porque no está contenida ni en una función de agregado ni en la cláusula GROUP BY
.
SELECT MIN(Grade) FROM Students GROUP BY Grade;
Explicación: Agrupar devolverá una lista de todas las calificaciones agrupadas por calificación. El enunciado desea que se devuelva solo una fila.
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
, eliminando duplicados, qué palabra clave puedes usar?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
no se puede usar con una función de agregado. GROUP BY
y ORDER BY
en el mismo campo. WHERE
debería usar el alias SubTotal
. 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_P ublisherID 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
del servidor. ¿Qué consulta deberías usar?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;
Todas las declaraciones deben finalizar con un punto y coma.
Todas las declaraciones deben operar en una tabla de datos.
Todas las declaraciones deben estar escritas siempre en letras mayúsculas.
Todas las declaraciones deben incluir más de una 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;
Error de conversión al convertir el valor varchar 'abc' al tipo de datos 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'; );
Obtendrás un error porque ROLLBACK elimina la fila que se actualizó
SELECT first_name, email FROM Students WHERE department = Humanities;
SELECT first_name, email FROM Students WHERE department = "Humanidades";
SELECT first_name, email FROM Students WHERE department = 'Humanidades';
SELECT 'first_name', 'email' FROM 'Students' WHERE 'department' = "Humanidades";
DROP TABLE Products.Inventory;
USE Products; DROP TABLE Inventory;
USE Products; DELETE Inventory;
USE Products.Inventory; DROP TABLE Inventory;
Esta declaración primero cambia a la base de datos Products usando el comando
USE
y luego elimina la tabla Inventory usando el comandoDROP TABLE
.
SELECT
, ¿qué cláusula se debe usar siempre con la cláusula TOP para indicar de manera predecible qué filas se ven afectadas por TOP?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;