– Create a table
CREATE TABLE Employee
(

Name varchar(50) NOT NULL,
Salary int NOT NULL

)

– Insert the values
INSERT INTO Employee(Name, Salary)
VALUES (‘e5′, 45000)

INSERT INTO Employee(Name, Salary)
VALUES (‘e3′,  30000)

INSERT INTO Employee( Name, Salary )
VALUES (‘e2′,  49000)

INSERT INTO Employee( Name, Salary )
VALUES (‘e4′,  36600)

INSERT INTO Employee( Name, Salary )
VALUES (‘e1′  ,  58000)

SELECT * FROM Employee

–Following queries will help you in finding the no of columns in a table
SELECT COUNT(*) NoOfColumns FROM Syscolumns where id = object_id(‘Employee’)

SELECT COUNT(*) NoOfColumns FROM Syscolumns where id = ( SELECT id from sysobjects  where name = ‘Employee’ )

SELECT COUNT(*) NoOfColumns FROM Information_Schema.[Columns] where table_name = ‘Employee’

–Happy Programming. Share Knowledge.

Pawan Kumar

Pawankkmr@hotmail.com

Advertisements