SETHA SITE INFORMATION

  • Increase font size
  • Default font size
  • Decrease font size
SETHA SITE INFORMATION

How to change data type of field in table using T-SQL?

E-mail Print PDF
Using below T-SQL script to change data type of the table's field in Microsoft SQL Server.
ALTER TABLE table_name
ALTER COLUMN column_name new_data_type;
 

How to rename column in SQL Server using T-SQL?

E-mail Print PDF
Suppose we have database named StudentDB and table named Student in Microsoft SQL Server 2008.
Below T-SQL code uses to rename column StdID of table Student to new column named StudentID.
USE StudentDB

EXEC sp_rename 'Student.StdID', 'StudentID','COLUMN'
 

How to Get Prime Number less than [n]?

E-mail Print PDF
This article shows a function that produce a set of prime numbers less number [n] in Java Programming. The function will return prime numbers in an array.
For example:
- If n=10 then prime number will be 2, 3, 5, 7
- If n=20 then prime number will be 2, 3, 5, 7, 11, 13, 17, 19

int[] getPrimeNumber(int n)
        {     
            int x[]=new int[n];
            int j=0;
            boolean isPrime=true;
            
            for(int i=2; i<=n;i++)
            {
                    if(i==2||i==3)
                    {
                        isPrime=true;
                    }
                    else{
                        isPrime=true;
                        for(int k=0; k<j; k++)
                        {                    
                                if(i%x[k]==0)
                                {
                                isPrime=false;
                                break;
                                }
                        }
                    }

                    if(isPrime==true)
                    {
                        x[j]=i;
                        j+=1;
                    }
            }

            int [] vals;
            vals=new int[j];
            System.arraycopy(x, 0, vals, 0, j);

            System.out.println("Show prime number less than "+n);
        
            return vals;
}
 

How to Add Foreign Key, Delete and Update CASCADE to Existing Table in T-SQL?

E-mail Print PDF
Microsoft SQL Server uses T-SQL (Transact SQL) to access database objects and manipulate data in the Database. If we create one Table and forgot to put a foreign key constraint including CASCADE options on a field that is a foreign key of other Table, we can use the following CODE.
ALTER TABLE table_name
WITH NOCHECK ADD CONSTRAINT fk_constraint_name
	FOREIGN KEY(foreign_key_field)
	REFERENCES reference_table(primary_key_field)
	[ON DELETE CASCADE]
	[ON UPDATE CASCADE]

For example, we have existing Tables as below:
student(id, stname, gender)
studentphone(id, phone_number)
 
Table studentphone is a child table of student but we forgot to put a foreign key constraint on field [id] in studentphone. To add a foreign key constraint on field [id] with CASCADE options in Table studentphone please see the code below.
ALTER TABLE studentphone
WITH NOCHECK ADD CONSTRAINT fk_student_phone
	FOREIGN KEY(id)
	REFERENCES studenet(id)
	ON DELETE CASCADE
	ON UPDATE CASCADE
 

How to get file name from a specified directory in C#.Net?

E-mail Print PDF
The below VB.Net code uses to get all document files (*.docx) in directory C:\Test\. For example, if we have 3 document files (.docx) in C:\Test\ directory then the below code will result those three files in full path on 3 message boxes sequentially. C# Code
string[] strFiles;
strFiles = System.IO.Directory.GetFiles("C:\\Test\\","*.docx");
foreach (string str in strFiles)
{
    MessageBox.Show(str);
}
 
  • «
  •  Start 
  •  Prev 
  •  1 
  •  2 
  •  3 
  •  4 
  •  5 
  •  6 
  •  7 
  •  8 
  •  9 
  •  10 
  •  Next 
  •  End 
  • »


Page 1 of 19