<commit_before>/*
	generate-table-xml.sql will document the Tables, Columns and Foreign keys from a database as an Xmldocument.
*/

select 
	tableXml
from 
	(
		select 
			'<Database name="'+ db.name 
			+ '" collation="' + db.collation_name 
			+ '" compatibilityLevel="' + cast(db.compatibility_level as varchar)
			+ '" createDate="' + cast(db.create_date as varchar)
			+ '">' as [tableXml],
			'0.1' as [sort_order]
		from 
			sys.databases db
		where 
			database_id = DB_ID()
	UNION ALL
		select
			'  <File name="' + mf.name 
			+ '" type="' + case when mf.type = 0 then 'Data' else 'Log' end 
			+ '" physical="' + mf.physical_name 
			+ '"/>' as [tableXml],
			'0.1.0' + cast(mf.file_id as varchar) as [sort_order]
		from 
			sys.master_files mf
		where 
			database_id = DB_ID()

	UNION ALL
		select 
			'  <Tables>' as [tableXml],
			'0.2' as [sort_order]
	UNION ALL
		select 
			'    <Table tableId="' + cast(object_id as varchar) + '" name="' + t.name + '">' as [tableXml],
			cast(object_id as varchar) + '.0' as [sort_order]
		from 
			sys.tables t
	UNION ALL
		select 
			'      <Rows count="' + cast(p.rows as varchar) + '"/>' as [xml],
			cast(t.object_id as varchar) + '.00' as [sort_order] 
		from
			sys.tables t	
		inner join
			sys.indexes i ON t.object_id = i.object_id
		inner join
			sys.partitions p ON i.object_id = p.object_id AND i.index_id = p.index_id
		where 
			t.name not like 'dt%' 
			and i.object_id > 255 
			and i.index_id <= 1
		group by 
			t.object_id, p.rows	
	UNION ALL
		select 
			'      <Column columnId="' + cast(c.column_id as varchar) 
			+ '" name="' + c.name 
			+ '" type="' + ty.name 
			+ '" maxLength="' + cast(c.max_length as varchar)
			+ '" precision="' + cast(c.precision as varchar)
			+ '" scale="' + cast(c.scale as varchar)
			+ '"/>' as [xml],
			cast(t.object_id as varchar) + '.' + right('00000' + cast(c.column_id as varchar), 3) as [sort_order]
			--* 
		from sys.tables t 
		inner join
			sys.columns c
		on t.object_id = c.object_id
		inner join 
			sys.types ty
		on c.user_type_id = ty.user_type_id 
		where t.type = 'U'
	UNION ALL
		select 
			'    </Table>' as [tableXml],
			cast(object_id as varchar) + '.999' as [sort_order]
		from 
			sys.tables t
	UNION ALL
		select
			'  </Tables>' as [tableXml],
			'99999999999999.999' as [sort_order]
	UNION ALL
		select
			'</Database>' as [tableXml],
			'99999999999999.9999' as [sort_order]	
	UNION ALL
		select	
			'      <ForeignKey name="' + fk.name 
			--+ '" tableId="' + cast(fkc.parent_object_id as varchar) 
			+ '" columnId="' + cast(fkc.parent_column_id as varchar)
			+ '" refTableId="' + CAST(fkc.referenced_object_id as varchar)
			+ '" refColumnId="' + CAST(fkc.referenced_column_id as varchar)
			+ '"/>' as [tableXml],
			cast(fkc.parent_object_id as varchar) + '.000.' + right('000' + cast(fkc.parent_column_id as varchar), 3) as [sort_order]
		from 
			sys.foreign_key_columns fkc
		inner join 
			sys.foreign_keys fk
		on 
			fk.object_id = fkc.constraint_object_id

	) qry
order by qry.sort_order
<commit_msg>Add Schema data<commit_after>/*
	generate-table-xml.sql will document the Tables, Columns and Foreign keys from a database as an Xmldocument.
*/

select 
	tableXml
from 
	(
		select 
			'<Database name="'+ db.name 
			+ '" collation="' + db.collation_name 
			+ '" compatibilityLevel="' + cast(db.compatibility_level as varchar)
			+ '" createDate="' + cast(db.create_date as varchar)
			+ '">' as [tableXml],
			'0.1' as [sort_order]
		from 
			sys.databases db
		where 
			database_id = DB_ID()
	UNION ALL
		select
			'  <File name="' + mf.name 
			+ '" type="' + case when mf.type = 0 then 'Data' else 'Log' end 
			+ '" physical="' + mf.physical_name 
			+ '"/>' as [tableXml],
			'0.1.0' + cast(mf.file_id as varchar) as [sort_order]
		from 
			sys.master_files mf
		where 
			database_id = DB_ID()

	UNION ALL
		select 
			'  <Tables>' as [tableXml],
			'0.2' as [sort_order]
	UNION ALL
		select 
			'    <Table tableId="' + cast(object_id as varchar) 
			+ '" schema="' + s.name
			+ '" name="' + t.name 
			+ '">' as [tableXml],
			cast(object_id as varchar) + '.0' as [sort_order]
		from 
			sys.tables t
		inner join
			sys.schemas s on s.schema_id = t.schema_id
	UNION ALL
		select 
			'      <Rows count="' + cast(p.rows as varchar) + '"/>' as [xml],
			cast(t.object_id as varchar) + '.00' as [sort_order] 
		from
			sys.tables t	
		inner join
			sys.indexes i ON t.object_id = i.object_id
		inner join
			sys.partitions p ON i.object_id = p.object_id AND i.index_id = p.index_id
		where 
			t.name not like 'dt%' 
			and i.object_id > 255 
			and i.index_id <= 1
		group by 
			t.object_id, p.rows	
	UNION ALL
		select 
			'      <Column columnId="' + cast(c.column_id as varchar) 
			+ '" name="' + c.name 
			+ '" type="' + ty.name 
			+ '" maxLength="' + cast(c.max_length as varchar)
			+ '" precision="' + cast(c.precision as varchar)
			+ '" scale="' + cast(c.scale as varchar)
			+ '"/>' as [xml],
			cast(t.object_id as varchar) + '.' + right('00000' + cast(c.column_id as varchar), 3) as [sort_order]
			--* 
		from sys.tables t 
		inner join
			sys.columns c
		on t.object_id = c.object_id
		inner join 
			sys.types ty
		on c.user_type_id = ty.user_type_id 
		where t.type = 'U'
	UNION ALL
		select 
			'    </Table>' as [tableXml],
			cast(object_id as varchar) + '.999' as [sort_order]
		from 
			sys.tables t
	UNION ALL
		select
			'  </Tables>' as [tableXml],
			'99999999999999.999' as [sort_order]
	UNION ALL
		select
			'</Database>' as [tableXml],
			'99999999999999.9999' as [sort_order]	
	UNION ALL
		select	
			'      <ForeignKey name="' + fk.name 
			--+ '" tableId="' + cast(fkc.parent_object_id as varchar) 
			+ '" columnId="' + cast(fkc.parent_column_id as varchar)
			+ '" refTableId="' + CAST(fkc.referenced_object_id as varchar)
			+ '" refColumnId="' + CAST(fkc.referenced_column_id as varchar)
			+ '"/>' as [tableXml],
			cast(fkc.parent_object_id as varchar) + '.000.' + right('000' + cast(fkc.parent_column_id as varchar), 3) as [sort_order]
		from 
			sys.foreign_key_columns fkc
		inner join 
			sys.foreign_keys fk
		on 
			fk.object_id = fkc.constraint_object_id

	) qry
order by qry.sort_order

{'fraction_non_alphanumeric': 0.1435483870967742, 'fraction_numerical': 0.02129032258064516, 'mean_word_length': 2.842007434944238, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 6}, 'pii_count': 0, 'substrings_counts': 4, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '338279', 'n_tokens_mistral': 2860, 'n_tokens_neox': 2364, 'n_words': 601}