如何 判断 sql server 数据库命名合法性?(17分)

  • 主题发起人 主题发起人 maill01
  • 开始时间 开始时间
M

maill01

Unregistered / Unconfirmed
GUEST, unregistred user!
如何 判断 sql server 数据库命名合法性?<br><br>如首个必须是字母,其他可为数字或字母,请写出函数!
 
sql server例子<br>1 判断用户输入是否合法,这个不难吧<br>2 连接master数据库查询select name from sysdatabases,循环比较是否和已有的数据库名字相同,这个也不难吧<br>ok搞定
 
function checksqlname(sqlname:string):boolean;<br>var<br>&nbsp; i:integer;<br>begin<br>&nbsp; result:= true;<br>&nbsp; for i:=1 to length(sqlname) do<br>&nbsp; begin<br>&nbsp; &nbsp; if i=1 then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; if not(Copy(sqlname,i,1)[1] in ['a'..'z','A'..'Z']) then<br>&nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; showmessage('不合法');<br>&nbsp; &nbsp; &nbsp; &nbsp; result:= false;<br>&nbsp; &nbsp; &nbsp; &nbsp; break;<br>&nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; end<br>&nbsp; &nbsp; else<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; if not(Copy(sqlname,i,1)[1] in ['a'..'z','A'..'Z','0'..'9']) then<br>&nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; showmessage('不合法');<br>&nbsp; &nbsp; &nbsp; &nbsp; result:= false;<br>&nbsp; &nbsp; &nbsp; &nbsp; break;<br>&nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; end<br>&nbsp; end;<br>end;
 
thanks Godfear,
 
接受答案了.
 
后退
顶部