Tuesday, 17 March 2015

sql server displayed all tables foreign keys

sql server displayed all tables foreign keys

sql server displayed all tables foreign keys



SELECT 
'ALTER TABLE ' +OBJECT_NAME(f.parent_object_id) AS TableName ,
' ADD CONSTRAINT ' + f.name AS ForeignKey, 
' FOREIGN KEY  (['+ COL_NAME(fc.parent_object_id,fc.parent_column_id) +'])'AS ColumnName,
' REFERENCES [' + OBJECT_NAME (f.referenced_object_id)+'] ' AS ReferenceTableName,'('+
COL_NAME(fc.referenced_object_id,fc.referenced_column_id) + ')'  AS ReferenceColumnName
FROM sys.foreign_keys AS f
INNER JOIN sys.foreign_key_columns AS fc ON f.OBJECT_ID = fc.constraint_object_id
INNER JOIN sys.objects AS o ON o.OBJECT_ID = fc.referenced_object_id

TableName ForeignKey ColumnName ReferenceTableName ReferenceColumnName 

ALTER TABLE profile ADD CONSTRAINT FK_User_UserId FOREIGN KEY  ([userId]) REFERENCES [User] (id)

ALTER TABLE UserAddress ADD CONSTRAINT FK_UserAddress_UserId FOREIGN KEY  ([userId]) REFERENCES [User] (id)

ALTER TABLE UserContact ADD CONSTRAINT FK_UserContact_UserId FOREIGN KEY  ([userId]) REFERENCES [User] (id)


sql server drop all tables foreign keys

sql server drop all tables foreign keys

sql server drop all tables foreign keys


SELECT 'ALTER TABLE  ' + OBJECT_NAME(parent_object_id) AS TableName ,
  'DROP CONSTRAINT  '+ OBJECT_NAME(OBJECT_ID) AS NameofConstraint
FROM sys.objects
WHERE type_desc LIKE 'FOREIGN_KEY_CONSTRAINT'--'%CONSTRAINT'
GO



TableName NameofConstraint

ALTER TABLE  profile DROP CONSTRAINT  FK_User_UserId
ALTER TABLE  UserAddress DROP CONSTRAINT  FK_UserAddress_UserId
ALTER TABLE  UserContact DROP CONSTRAINT  FK_UserContact_UserId

enum in c#

enum in c#

enum in c#


  public enum UserType
    {
        Admin,
        Manager,
        Employee
    }


   public class ProfileResponse
    {

        public long id { get; set; }
        public long user_id { get; set; }
        public string first_name { get; set; }
       public int userType { get; set; }
   }


Profile profile = Db.GetBy<Profile>(x => x.userId == user_id);
var response = new ProfileResponse();
            response.id = profile.id;
            response.user_id = profile.userId;
            response.first_name = profile.firstName;
           response.userType = getUserType(profile.userId);






public int getUserType(long userId)
        {
            int type = 0;
            var user = (from u in Db.Users where u.id == userId select u.Type).FirstOrDefault();

            if (user == UserType.Admin)
            {
                type = 0;
            }
            else if (user == UserType.Manager)
            {
                type = 1;
            }
            else if (user == UserType.Employee)
            {
                type = 2;
            }
            return type;
        }




create random password in c# asp.net

create random password in  c# asp.net

create random password in  c# asp.net


string pwd = Guid.NewGuid().ToString("d").Substring(1, 5);


Ans:
5caf9
27dae