sql语言:如何判断字段是否存在,如何删除及创建字段
如何判断字段是否存在
if col_length('表名','字段1') is null ALTER TABLE 表名 ADD 字段1 Nvarchar(50) if col_length('表名','字段2') is null ALTER TABLE 表名 ADD 字段2 Nvarchar(50) ");
删除字段
if col_length('表名','字段1,') is not null ALTER TABLE 表名 drop column 字段1, column 字段2,column 字段3
创建字段
ALTER TABLE 表名 ADD 字段1 Nvarchar(50) , 字段2 INT NULL
相关文档:
应用中发现sql中的and及or的执行效率问题
sql语句,为什么把最后的or换成and,查询的就很快,使用的是mssql范例中northwind数据库为例,
select * from Orders a left join [Order Details] b on a.orderid = b.orderid
where a.customerid like '%ics%' or b.productid in (42,72)
追踪了语句的执行方案,发现 ......
从Table 表中取出第 m 条到第 n 条的记录:(Not In 版本)
SELECT TOP n-m+1 *
from Table
WHERE (id NOT IN (SELECT TOP m-1 id from Table ))
--从TABLE表中取出第m到n条记录 (Exists版本)
SELECT TOP n-m+1 * from TABLE AS a WHERE Not Exists
(Select * from (Select Top m-1 * from TABLE orde ......
Student(S#,Sname,Sage,Ssex) 学生表
Course(C#,Cname,T#) 课程表
SC(S#,C#,score) 成绩表
Teacher(T#,Tname) 教师表
问题:
1、查询“001”课程比“002”课程成绩高的所有学生的学号;
select a.S# from (select s#,score from SC where C#='001') a,(select s#,score
fr ......
1、查询两个时间之间
select * from [tablename] where date between \'value1\' and \'value2\'
2、显示最后回复时间
select a.title,a.username,b.adddate from table a,(select max(adddate) adddate from table where table.title=a.title) b
3、日程安排提前5分钟提醒
select * from 日程安排 w ......
2010-05-05 13:35:52.06 Server Microsoft SQL Server 2005 - 9.00.1399.06 (Intel X86)
Oct 14 2005 00:33:37
Copyright (c) 1988-2005 Microsoft Corporation
Developer Edition on Windows NT 5.1 (Build 2600: Service Pack 3)
2010-05-05 13:35:52.06 Server (c) 2005 Microsoft Corporation.
201 ......