Database design, maintenance is as long as the problem, often to query data and view the original field defined what was meant. Use sp_help to look at it? Slow to have to recall the original intention of the half-day design. Start, as long as the design work to spare, you can very easy access to the original design of the database. First, we create a data table, give the table and each field with Chinese comments. As follows:
- CREATE TABLE Employee (
- EmpIDintNOT NULL, – employee number
- EmpName varchar (32), – the name of the employee
- EmpPhone varchar (32) – Employee phone
- EmpStateint– Employee Status [1: on-the-job 2: left]
- )
- ;
- ALTER TABLE Employee ADD CONSTRAINT PK_Employee
- Primary KEY clustered (empid)
- ;
- To EXEC sp_addextendedproperty‘MS_Description’, ‘staff table’, ‘User’, dbo, ‘table’, Employee
- ;
- EXEC sp_addextendedproperty‘MS_Description’, ‘Employee Number’, ‘User’, dbo, ‘table’ Employee, ‘column’, empid
- ;
- EXEC sp_addextendedproperty‘MS_Description’, ‘the staff Name’, ‘user’, dbo, ‘table’ Employee, ‘column’, EmpName
- ;
- The EXEC sp_addextendedproperty‘MS_Description’, ’employee telephone’, ‘User’, dbo, ‘table’ Employee, ‘column’, EmpPhone
- ;
- EXEC sp_addextendedproperty‘MS_Description’, ’employee status [1: on-the-job, 2: Separation]’, ‘User’, dbo, ‘table’ Employee, ‘column’, EmpState
- ;
Then, create a stored procedure, as follows:
- Create procedure DataDictionary_GetbyTableName
- @ TableName varchar (32)
- as
- select b. [name] Tablename, Isnull (c. [name], ‘Table’) ColName, convert (varchar (256), a. [value]) Description
- from sys.extended_properties a inner join sysobjects b on b.id = a.major_id
- left join syscolumns c on a.minor_id = c.colid and a.major_id = c.id
- where b. [name] = @ TableName
Finally, the need to view a table, execute the stored procedure + table name. On it. As follows:
- DataDictionary_GetbyTableName employee
Get is:
Did not feel convenient.