Create one Student table where is ID, Name, Semester, City colums. Find the solution that we can insert just the 3rd semester students. This mean that the user connot inser Student who are in 1, 2, or 4th semester.
1 2 3 4 5 6 7 8
DROPTABLE IF EXISTS Student;
CREATE TABLE Student ( ID INTPRIMARY KEYIDENTITY(1, 1), Semester TINYINT CHECK(Semester =3) NOT NULL, NAME TEXT NOT NULL, City TEXT NOT NULL, );
Create one method, what filtering the same record and give back just once. For example, if we have 3 pizza with 450 price, if we take a Select, then results will be just 1 pizza, not 3 pizza.
You have 2 products. The coffee is 245, the pizza is 475. (Coins: 20, 10, 5) Please count how many coins need it if we would like to buy this products.
INSERT INTO TXML VALUES ('Some', 'Thing'), ('Body', 'Any');
SELECT*FROM TXML FOR XML AUTO;
事务
用事务填充表。
Create one table with 900 records.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
DROPTABLE IF EXISTS Fill;
CREATE TABLE Fill( Id INTPRIMARY KEYIDENTITY, Increse INT );
BEGIN TRAN DECLARE@indexINT SET@index=0
WHILE @index<900 BEGIN INSERT INTO Fill VALUES (@index) SET@index=@index+1 END
COMMIT TRAN
用户账户
创建新用户并授予其权限。
Create a new account, which log in via system administrator with data reader persmission.
1 2 3
CREATE LOGIN [DGYY] WITH PASSWORD=N'123', DEFAULT_DATABASE=[master] ALTER SERVER ROLE [sysadmin] ADDMEMBER [DGYY] ALTER ROLE [db_datareader] ADDMEMBER [DGYY]
UNION
合并多个 SELECT 语句的结果集
How can we use the data of set?
1 2 3
SELECTNULLFROM SomeTable UNION SELECTNULLFROM OtherTable;
CASE WHEN
用 CASE 写一个判断
Create one new table for cars(Id, type, color). After this, select one car from the table and compare this car color on the next logical statement the car is Black (True, False) Or White.