.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Articles >> DataBase >> Post New Resource Bookmark and Share   

 Subscribe to Articles

Create User Defined Data Types With Step by Step

Posted By:Ravi Ranjan Kumar       Posted Date: June 25, 2011    Points: 200    Category: DataBase    URL: http://www.dotnetspark.com  

This article enable you to learn how to make own user defined data types in SQL server using Step by Step Wizards
 

You can create User Defined Data Types in SQL server management Studio using given steps

You need to use Object Explorer to create User Defined Data Types

Follow the Given Steps in Below Images

 Step 1 :- In Object Explorer Expand Databases, and then select any database (as your requirement)

 Step 2 :- Expand Selected Database

 Step 3 :- Expand Programmability and  then Right Click on Types and Then select user-Defined Data Types and open it 


 Step 4 :- In the New User-defined Data Type dialog box, in the Schema box, type the schema to own this data type, or use the browse button to select the schema. After browse button you need to follow 6 and 7 steps to choose Schema name.


 Step 5 :-  In the Name box, type a name for the new data type. Take a look at step 8 at given image. 
 Step 6 :- In the Data type box, select the data type that the new data type will be based on. [ You can see step 9 in given image ]


Step 7 :- Complete the Length, Precision, and Scale boxes if appropriate for that data type.

Step 8 :- Check Allow NULLs if the new data type can permit NULL values.


In the Binding area, complete the Default or Rule boxes if you want to bind a default or rule to the new data type. Defaults and rules cannot be created in SQL Server Management Studio. Use Transact-SQL. Example code for creating defaults and rules are available in Template Explorer.

After creating You can see that a user defined data type is created [Example UniqueID]


How to use These UserDefined data type 

You can use these user define data type  while creating table 

Or you can use SQL query as

CREATE TABLE [dbo].[EmployeeDetails](
	[EmpID] [dbo].[UniqueID] NOT NULL,
	[EmpName] [char](30) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL
) ON [PRIMARY]
 You can verify after creating table

 


Additional Information

 If you want to take a look about it dependencies Means user defined data type where using so you can follow given steps in below images



And click on View Dependencies 


 Subscribe to Articles

     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend