T-SQL
1. Arithmetic Operations, logical operations, comparison operations, bit operations, string connection operations, etc.
2. Program Structure
Sequence Structure, select structure, and Cycle Structure
I. Classic applications with a structure selected
-- Define three variables
Declare @ hyuser varchar (50), @ hypwd varchar (50), @ MSG varchar (50)
-- Query the value of a Variable
Select @ hyuser = 'liping', @ hypwd = '000000'
-- Determine whether the values of the following variables are equal to the values of the queried variables.
If @ hyuser = 'hystu1'
Begin
If @ hypwd = '20140901'
Set @ MSG = 'logon successful'
Else
Set @ MSG = 'incorrect password'
End
Else if @ hyuser = 'hystu2'
Begin
If @ hypwd = '20140901'
Set @ MSG = 'logon successful'
Else
Set @ MSG = 'input error'
End
Else if @ hyuser = 'hystu3'
Begin
If @ hypwd = '20140901'
Set @ MSG = 'logon successful'
Else
Set @ MSG = 'logon failed'
End
Else
Set @ MSG = 'user name is incorrect. Please log on again'
Print @ msg
Go
==================
Determine whether the user name exists, whether the user password is correct, and whether the user is successfully logged on to the system with a prompt
------- Create a table in the database
Use master
Create Table hyuser (
Hyid int identity (1, 1) primary key,
Hyname varchar (50) unique,
Hypwd varchar (50)
)
-------- insert a record to the table
insert into hyuser (hyname, hypwd) values ('stu1', '000000')
insert into hyuser (hyname, hypwd) values ('stu2', '123')
insert into hyuser (hyname, hypwd) values ('stu3', '123 ')
---------- program writing
declare @ hyuser varchar (50), @ hypwd varchar (50), @ MSG varchar (50), @ num int,
@ num1 int
select @ hyuser = 'stu1', @ hypwd = '000000'
select @ num = count (*) from hyuser where hynam E = @ hyuser
If @ num> = 1
begin
select @ num1 = count (*) from hyuser where hyname = @ hyuser and hypwd = @ hypwd
If @ num1> = 1
set @ MSG = 'login successful! '
else
set @ MSG =' the password is incorrect. Please enter it again! '
end
else
set @ MSG =' the user name is incorrect. Please enter it again! '
Print @ MSG
go