-- To find all database names;
select name from sys.databases;
-- To find all table names under a database
use DBName;
go
select name from sys.tables;
-- To get column name, data type and length of a table
SELECT
c.name 'Column Name',
t.Name 'Data type',
c.max_length 'Max Length'
FROM
sys.columns c
INNER JOIN
sys.types t ON c.system_type_id = t.system_type_id
WHERE
c.object_id = OBJECT_ID('UserInfo')
本文介绍了使用SQL进行数据库操作的实用技巧,包括查找所有数据库名称、获取特定数据库下所有表名,以及检索表中列名、数据类型和长度的方法。这些技巧对于数据库管理和应用开发非常有用。

2052

被折叠的 条评论
为什么被折叠?



