SQL2000语句,创建数据表怎么设置主健和默认值
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了SQL2000语句,创建数据表怎么设置主健和默认值相关的知识,希望对你有一定的参考价值。
参考技术A CREATE TABLE 表名(
字段1 int IDENTITY NOT NULL PRIMARY KEY, --通过PRIMARY KEY设定主键
字段2 varchar(30) NOT NULL,
字段3 smalldatetime NOT NULL DEFAULT GETDATE() --通过DEFAULT value设定默认值
);
祝你成功!
如何从数据库查询各表中所有存在默认值的字段
如题,执行添加字段注释的时候不小心忽略了默认值约束,覆盖了很多字段,现已回滚,想执行一条sql语句查询出数据库中200多张表所有存在默认值的字段,手动找出效率太低。
-- sql server我就知道,其他没用过。-- tableName表名,sqlName列名,defaultVal就是默认值,字符串表示
SELECT
a.colorder as colOrder,
d.name as tableName,
a.name as sqlName,
convert(int,case when COLUMNPROPERTY( a.id,a.name,'IsIdentity')=1 then 1 else 0 end) as isIndex,
convert(int,case when exists(SELECT 1 FROM sysobjects where xtype='PK' and parent_obj=a.id and name in (
SELECT name FROM sysindexes WHERE indid in( SELECT indid FROM sysindexkeys WHERE id = a.id AND colid=a.colid))) then 1 else 0 end) as isPk,
b.name as sqlTypeName,
a.length as 'length',
convert(int,COLUMNPROPERTY(a.id,a.name,'PRECISION')) as 'size',
convert(int,isnull(COLUMNPROPERTY(a.id,a.name,'Scale'),0)) as 'scale',
convert(int,case when a.isnullable=1 then 1 else 0 end) as 'nullable',
convert(varchar(100), isnull(e.text,'')) as defaultVal,
convert(varchar(255), isnull(g.[value],'')) as remarks
FROM
syscolumns a
left join
systypes b
on
a.xusertype=b.xusertype
inner join
sysobjects d
on
a.id=d.id and d.xtype='U' and d.name<>'dtproperties'
left join
syscomments e
on
a.cdefault=e.id
left join
sys.extended_properties g
on
a.id=G.major_id and a.colid=g.minor_id
left join
sys.extended_properties f
on
d.id=f.major_id and f.minor_id=0
where 1=1
-- d.name=?
order by
a.id,a.colorder 参考技术A 假如你要查看user1用户下的所有表:
以user1身份登录oracle,然后执行:
select table_name from user_tables;
或
select table_name from tabs;
以上是关于SQL2000语句,创建数据表怎么设置主健和默认值的主要内容,如果未能解决你的问题,请参考以下文章
怎么在sql servler2000中建立一个序列,用sequence写的