Check constraint..................
Create Table Books
(
BookID varchar(8) primary key
check (BookID LIKE 'B[0-9][0-9][0-9][0-9][0-9]'),
Title varchar(50) NOT NULL,
Author varchar(50) NOT NULL,
Publisher varchar(50) NULL,
Category varchar(10) NOT NULL check (Category in ('Tech','Busi','Arts')),
Price int NOT NULL CHECK (Price >=0),
NoBookInHand int NOT NULL check (NoBookInHand>=0)
);
In this table you can enter data where the following must be satisfied:-
BookID must be first character B and Rest five are number.
Category must in ('Tech','Busi','Arts')
Price is not negative
NoBookInHand is not negative.
Add Check Constraint:
ALTER TABLE TableName
ADD CONSTRAINT ConstraintName CHECK (Condition......)
Drop Check Constraint:
ALTER TABLE TableName
DROP CONSTRAINT ConstraintName
02 February, 2011
Combine Multiple Records Comma Separated In One Column MSSQL 2005
In this example i am going to describe how to combine multiple records in a column in MS SQL into one record comma separated.
Here is the scenario
I have a table having Employees names and their respective Department names, now i want to show Employees names separated by comma into one column and respective Department name in another column.
My table schema is shown in the image below

And this is Data into table

I want output in following format
Department---------------FirstName
IT----------------------amiT,Emp1,Emp5
Admin-------------------Shobhit, Emp3,Emp7
and so on
To get this desired result we need to write below mentioned query
SELECT DISTINCT Department,
EmpNames = substring( ( SELECT ', ' + FirstName
FROM Employees e2
WHERE e2.Department = e1.Department FOR XML path(''), elements),2,500)
FROM Employees e1
And the output of this SQL Query would be
Here is the scenario
I have a table having Employees names and their respective Department names, now i want to show Employees names separated by comma into one column and respective Department name in another column.
My table schema is shown in the image below
And this is Data into table
I want output in following format
Department---------------FirstName
IT----------------------amiT,Emp1,Emp5
Admin-------------------Shobhit, Emp3,Emp7
and so on
To get this desired result we need to write below mentioned query
SELECT DISTINCT Department,
EmpNames = substring( ( SELECT ', ' + FirstName
FROM Employees e2
WHERE e2.Department = e1.Department FOR XML path(''), elements),2,500)
FROM Employees e1
And the output of this SQL Query would be
27 January, 2011
No need to know old password for change password in LAN?
Open Command Prompt.....
Then C:\>net user username newpassword
for example: your user name imran and change password to 786786786
C:\>net user imran 786786786
N.B.: You must login as a administrator
Then C:\>net user username newpassword
for example: your user name imran and change password to 786786786
C:\>net user imran 786786786
N.B.: You must login as a administrator
Subscribe to:
Posts (Atom)