create SQL Server table based on a user defined type
--Create table variable from type.
DECLARE @Table AS dbo.MyTableType
--Create new permanent/physical table by selecting into from the temp table.
SELECT *
INTO dbo.NewTable
FROM @Table
WHERE 1 = 2
--Verify table exists and review structure.
SELECT *
FROM dbo.NewTable
create table based on a user defined type
Have you tried:
create table test_type_table of test_type;
Is it possible to use user defined table type inside another user defined table type in sql
No. Why would it be? That's not how SQL Server (or any relational database, for that matter) work.
From TechNet's page on User-Defined Table Types:
Restrictions
User-defined table types have the following restrictions:
- A user-defined table type cannot be used as a column in a table or a
field in a structured user-defined type.
"Nesting" in relational databases are achieved by using Foreign keys
You can't even create a foreign key constraint between two user defined table types.
What you can do is create two table types that one of them have a column to keep the id of the other, like this:
CREATE TYPE A AS TABLE
(
A_Id int
)
GO
CREATE TYPE B AS TABLE
(
B_Id int,
A_Id int -- "FK"
)
GO
Create an Alias to a user defined table type in a different schema
Quote from comment on the original question:
Alias data types are for scalar data types, you can't create an alias data type of a table type. You'll need to give explicit access to the types on the schema here so that the USER's can declare a parameter of the type. –
User: Larnu
He gave me a couple of keywords which helped with my google search.
https://learn.microsoft.com/en-us/sql/t-sql/statements/grant-type-permissions-transact-sql?view=sql-server-ver15
It is still weird though, as I had allow execution and after giving them rights on the specific stored procedure, I could then remove the rights and it works. Trying to remove the rights first results in the execution failing.
Related Topics
Should a Composite Primary Key Be Clustered in SQL Server
Spark Dataframe Nested Case When Statement
Why Is Union Faster Than an or Statement
How to Find the User That Has Both a Cat and a Dog
How to Subtract 2 Dates in Oracle to Get the Result in Hour and Minute
SQL Recursion Without Recursion
Insert into a Row at Specific Position into SQL Server Table with Pk
How to Create Xml Schema from an Existing Database in SQL Server 2008
Interesting Tree/Hierarchical Data Structure Problem
Row_Number() Over Not Fast Enough with Large Result Set, Any Good Solution
How to Use SQL Wildcards in Linq to Entity Framework
How to Determine the Primary Key for a Table in SQL Server
Get Top 10 Products for Every Category
How to Remove Duplicates from Table Using SQL Query
Search All Databases for Value
"Similar Posts" Like Functionality Using Ms SQL Server
Split/Explode Comma Delimited String with Sybase SQL Anywhere