-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLevel-2
More file actions
27 lines (22 loc) · 731 Bytes
/
Level-2
File metadata and controls
27 lines (22 loc) · 731 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
/* Level 1
-------
Write a Stored Procedure that takes table name as input parameter and finds out the name of all the columns in table.
Constraint: You cannot use sp_columns statement.
*/
CREATE PROCEDURE TableColumnsName
@NameOfTable NVARCHAR(50)
AS
BEGIN
-- Check the table is present in the database or not
IF NOT EXISTS (SELECT 1 FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = @NameOfTable)
BEGIN
RAISERROR('Table not found.', 16, 1)
RETURN;
END
-- Now select the names of all the columns
SELECT COLUMN_NAME
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = @NameOfTable
ORDER BY ORDINAL_POSITION;
END;
EXEC TableColumnsName @NameOfTable = 'StudentDetails';