Showing posts with label base. Show all posts
Showing posts with label base. Show all posts

Wednesday, March 21, 2012

Primary key in views.(SQL Server 2005)

Hello,

When I use MSSQL Server 2000, primary key in views(The primary key of base table) detected by sql server 2000.
But, new version (2005) do not this, that mean when I "Modify" a view in Enterprise Manager, there is not any Identity filed in list and I have some problem in my programming.
Please help me.Not sure I understand the request. What are you trying to modify. You can always use query editor to create/alter/modify a view's definition.

Can you elaborate more.

Primary Key in View

how to create view in sql server 2005 that recognize Identity And Primary key of base tableif you want to know about the metadata in SQL Server Server like Constraints / Tables etc. you can use the INFORMATION_Schema Views, in this case you would query the INFORMATION_SCHEMA.Constraints view.

HTH, Jens Suessmeyer.

http://www.sqlserver2005.de

|||

SELECT COLS.table_schema
,COLS.Table_name
,COLS.COLUMN_NAME
,cols.CONSTRAINT_NAME
,ac.IS_identity
FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE AS COLS
INNER JOIN INFORMATION_SCHEMA.TABLE_CONSTRAINTS CONS
ON COLS.CONSTRAINT_NAME = CONS.CONSTRAINT_NAME
JOIN sys.all_columns ac
ON OBJECT_NAME(ac.object_id) = COLS.table_name
AND ac.name=COLS.COLUMN_NAME
WHERE CONS.CONSTRAINT_TYPE LIKE 'PRIMARY KEY'
ORDER BY COLS.CONSTRAINT_NAME, COLS.ORDINAL_POSITION

as i wrote this pretty quick and didnt test it fully.. using it is on your own risk ;)

Guldmann, platon.dk