Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

In Oracle PL/SQL scripts, you can declare a variables using the syntax tablename%rowtype for its type. This will make that variable have the same "type" as a row of that table

(i.e. a it will be a structure with the same field names and types).

This is a convenient way to transfer data between database tables and PL/SQL.

I am looking at doing the same thing (Data Type) in Microsoft SQL Server 2008. Is there an equivalent feature?

share|improve this question

1 Answer 1

up vote 3 down vote accepted

No version of SQL Server has this. It would be useful (PostreSQL has the same and I like it).

In SQL Server, there are table types (CREATE TYPE), temporary tables (CREATE TABLE #foo) and table variables (DECLARE @var TABLE), but you can't mimic or inherit a table definition using %TYPE or CREATE TABLE .. INHERITS/OF

share|improve this answer
    
Thanks , But i think it's very perfect data type in oracle (i mean "table%rowtype") , and i don't know why MS SQl have not it –  Ali Sarshogh Jul 4 '13 at 7:33
    
@gbn: Can't the SELECT INTO be used to create a table of the same type as an existing table? –  ypercube Jul 4 '13 at 8:50
    
@ypercube: yes, but limited. You have no keys and can't be used in parameters like PG CREATE FUNCTION. It's nowhere as near as useful and I can't see how it replaces the %TYPE concept. –  gbn Jul 4 '13 at 8:56

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.