初学者提问,老手可以做练手

clamli007 2009-03-10 10:43:06
定义一个SQL语句
SQL语句是从数据库查询是否存在表格A,返回一个布尔值
如果返回值为真
{
继续判断表格A是否=3列,
如果否,自动添加3列,列名为A B C
}
则是如果返回值为否
{
弹出对话框信息“您输入的信息有误”
}


谢谢大家了~
...全文
126 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
yygyogfny 2009-03-11
  • 打赏
  • 举报
回复

alter procedure pr_Test
as
begin
if exists (select * from sysobjects where name = 'a' and type = 'u')
begin
declare @cols int
select @cols = count(1) from sysobjects o
inner join syscolumns c on o.id = c.id
where o.type = 'u' and o.name='a'

if(@cols <> 3)
begin
alter table test2 add a int
alter table test2 add b int
alter table test2 add c int
end
select 1
end
else
begin
select 0
end

end

wts_net 2009-03-11
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 Occam 的回复:]
查系统表也很方便,另外.net 2.0开始提供了架构查询的方法

SqlConnection.GetSchema("Tables", new string[] { null, null, null, "BASE TABLE" });
OleDbConnection.GetSchema("Tables", new string[] { null, null, null, "TABLE" });
查找列则用Columns

限制值参考:
ms-help://MS.MSDNQTR.v90.chs/wd_adonet/html/7ab93b89-1221-427c-84ad-04803b3c64b4.htm
[/Quote]
同意
occam 2009-03-11
  • 打赏
  • 举报
回复
查系统表也很方便,另外.net 2.0开始提供了架构查询的方法

SqlConnection.GetSchema("Tables", new string[] { null, null, null, "BASE TABLE" });
OleDbConnection.GetSchema("Tables", new string[] { null, null, null, "TABLE" });
查找列则用Columns

限制值参考:
ms-help://MS.MSDNQTR.v90.chs/wd_adonet/html/7ab93b89-1221-427c-84ad-04803b3c64b4.htm
liu4545533 2009-03-11
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 yygyogfny 的回复:]
SQL code
alter procedure pr_Test
as
begin
if exists (select * from sysobjects where name = 'a' and type = 'u')
begin
declare @cols int
select @cols = count(1) from sysobjects o
inner join syscolumns c on o.id = c.id
where o.type = 'u' and o.name='a'

if(@cols <> 3)
begin
alter table test2 ad…
[/Quote]

上面得 写法很好
格拉 2009-03-11
  • 打赏
  • 举报
回复
UP
clamli007 2009-03-11
  • 打赏
  • 举报
回复
判断是否有车次表

否则返回失败信息
是则判断始发站与终点站是否分别在STARTSTATION与ENDSTATION中

否则返回失败信息
是则判断是否列名>8列

否则添加10列日期信息(即日起10列,诸位嫌麻烦可以用其他代替)
是则查询票务信息

根据用户若干天日期判断始发站与终点站之间是否有票(所需区间>=1)(这里给个格式就可以了,我要在车次表下面某一列中搜索N行数字取得最大值是否等于某值,这里大家可以从简)
否则返回失败信息
是则查询票务信息(以下内容我会。。。)



以上内容全部用.NET制作,但是苦于才疏学浅,实在完成不了
希望大家能帮我写一段参考,我也可以同时学习下。
谢谢了
simonezhlx 2009-03-10
  • 打赏
  • 举报
回复
查系统表,如楼上
wuyi8808 2009-03-10
  • 打赏
  • 举报
回复
select *
from sysobjects
where xtype='U' and name='你要找的表名'

111,126

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧