不同數據庫中獲得表名列表的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'