AND
, IN
, LIKE
, और सभी किस श्रेणी के होते हैं?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
क्लॉज में भरना चाहिए?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;
यहां तालिका की तस्वीर महत्वपूर्ण है और यहां देखा जा सकता है कि केवल दो मान हैं जिनके पास न्यूनतम अंक हैं। दूसरा, पिछला उत्तर गलत था क्योंकि
DESC
से छोटे अंकों को परिणाम सूची के शुरू में डालेगा औरTOP(2)
पहले दो उच्चतम अंकों को ले लेगा, और हमें न्यूनतम अंक चाहिए।
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
का परिणाम _ पंक्तियों के साथ होगा।WHERE
क्लॉज़ उपयोग करेंगे?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'
अंडरस्कोर किसी भी एकल वर्ण को मेल खाता है, इसलिए आपको वास्तविक
_
को वर्ग ब्रैकेट के साथ लपेटना चाहिए, अन्यथा यह '1013', '10A3' आदि से समाप्त हो सकता है।
FROM
श्रेणी में कोई ज्वाइन प्रकार निर्दिष्ट नहीं किया जाता है, तो किस प्रकार का ज्वाइन माना जाता है?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 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
यहांdbo
एक स्कीमा है और इन्वेंटरी भी एक स्कीमा है। यदि हम एक डेटाबेस को निर्दिष्ट करना चाहते हैं तो हमेंdb_name.schema_name.table_name
का उपयोग करना चाहिए।
INNER JOIN
का परिणाम क्या होता है?ोते हैं, चाहे उनके पास तालिका2 में कोई संबंधित पंक्ति हो या न हो
TRUNCATE TABLE Students;
TRUNCATE * FROM Students;
DROP TABLE Students;
REMOVE * FROM Students;
CREATE TABLE
वक्तव्य के बारे में सोचें। जब किसी खाली स्थान में रखा जाता है, तो क्या विकल्प सुनिश्चित करता है कि BookISBN स्तंभ में कोई भी पुन: संख्यात्मक मान न हो?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;
व्याख्या: कॉलम Students.Grade
ORDER BY
क्लॉज में अमान्य है क्योंकि यह किसी एकल क्रिया या GROUP BY
क्लॉज में शामिल नहीं है।
SELECT MIN(Grade) FROM Students GROUP BY Grade;
व्याख्या: समूहीकरण सभी ग्रेडों की एक सूची लौटाएगा जो ग्रेड द्वारा समूहीकृत हैं। प्रॉम्प्ट केवल एक लौटाएगा गया पंक्ति चाहता है।
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
कोई भी रिकॉर्ड संशोधित होने पर हर बार तालिकाB में एक रिकॉर्ड जोड़ा जाए। आप किस तकनीक का अमल करने की सोच रहे हैं?
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 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
वक्तव्यों के परिणामों को मिलाकर, डुप्लिकेट को हटाकर, आप कौन सा कीवर्ड प्रयोग कर सकते हैं?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
वाक्यांश को एक संग्रह कार्य से उपयोग किया जा नहीं सकता है। GROUP BY
और ORDER BY
उसी क्षेत्र के साथ नहीं कर सकते। WHERE
वाक्यांश को 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_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
निर्देशिका में एक सरल डेटाबेस बैकअप बनाने की आवश्यकता है। आप कौन सा क्वेरी प्रयोग करेंगे?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;
सभी वाक्यों के साथ एक सेमीकोलन होना चाहिए।
सभी वाक्यों को डेटा तालिका पर ऑपरेट करना चाहिए।
सभी वाक्यों को हमेशा अपरकेस अक्षरों में लिखना चाहिए।
सभी वाक्यों में एक से अधिक चर शामिल होना चाहिए।
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;
यह वाक्यांश पहले
USE
आदेश का उपयोग करके उत्पाद डेटाबेस में जाता है और फिर तालिका इन्वेंट्री कोDROP TABLE
आदेश का उपयोग करके हटा देता है।
SELECT
वाक्यांश में, TOP
विधि के साथ हमेशा कौन सा वाक्यांश प्रयोग किया जाना चाहिए ताकि 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;