SQLserver表结构操作

 不同数据库中获得表名列表的SQL

记得大学那时刚学SQL Server,还为这个问题困惑过。今天偶然看到一篇网友的文章,涉及到这个问题,就整理出来了。
Oracle
SELECT TABLE_NAME FROM USER_TABLES ORDER BY TABLE_NAME

MySQL
SHOW TABLES

MS SQL Server
select name from sysobjects where type = N'U' order by name

DB2 UDB
SELECT NAME FROM SYSIBM.SYSTABLES WHERE TYPE = 'T' AND CREATOR != 'SYSIBM' ORDER BY NAME

--只能在当前库中更新对象名称
sp_rename oldName,newName

--Drop table命令用于删除一个表格或者表中的所有行
drop table 'tblName'

--添加列
alter table<表名> add<新列名><数据类型>

--将表   customers   中的列   contact   title   重命名为   title。
  EXEC   sp_rename   'customers.[contact   title]',   'title',   'COLUMN'  

--删除aaa表中的b字段
alter table aaa drop column b

--修改表aaa字段c的数据类型为varchar(30)
Alter Table aaa Alter Column c varchar(30)

--获取列的数据类型
select   d.name,a.name   ,b.name   ,a.length,   a.isnullable  
from   syscolumns   a,   systypes   b,sysobjects   d  
where d.name!='dtproperties' and   a.xtype=b.xusertype   and   a.id=d.id   and   d.xtype='U'
 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章