1. Query all database names in the database:
SELECT Name from Master. sysdatabases ORDER by Name
2. Query all the table names in a database:
SELECT name from SysObjects Where xtype= ' U ' ORDER by Name
3. Query table structure information:
1 SELECT (case if A.colorder=1 then d.name else null end) Table name, 2 a.colorder field ordinal, a.name field name, 3 TY (a.id,a.name, ' isidentity ') =1 then ' √ ' else ' end) identifier, 4 (SELECT count (*) from sysobjects 5 WHERE (name in (select name from sysindexes 6 where (id = a.id) and (Indid in 7 (select Indid from Sysindexkeys 8 where (id = a.id ) and (Colid in 9 (SELECT colid from syscolumns WHERE (id = a.id) and (name = A.name)))))) and (xtype = ' PK ') ">0 Then ' √ ' else ' end) primary key, B.name type, A.length occupies bytes, one columnproperty (a.id,a.name, ' PRECISION ') as length, IsNull (COLUMNPR Operty (a.id,a.name, ' scale '), 0) as decimal place, (case time a.isnullable=1 then ' √ ' else ' end) allow null, IsNull (E.text, ') default value, Isnul L (G.[value], ') as [description]14 from syscolumns A and left join Systypes B on a.xtype=b.xusertype inner join sysobjects D On a.id=d.id and d.xtype= ' U ' and d.name<> ' dtproperties ' of left joins syscomments E on a.cdefault=e.id-left join Sys.extended_propertiesG on a.id=g.major_id and A.colid=g.minor_id19 left join Sys.extended_properties F on D.id=f.class and f.minor_id=020 where B.name is not null21--where d.name= ' table to query '--if only the specified table is queried, add this condition to the order by A.id,a.colorder
How SQL Server gets the names of all the tables in a database, the names of all the fields in a table