Saturday, January 30, 2010

Change Column Name, Table Name in SQL Server, sp_rename

Syntax:

sp_rename [ @objname = ] 'object_name' , [ @newname = ] 'new_name'
[ , [ @objtype = ] 'object_type' ]

Arguments:

[ @objname = ] 'object_name'

Is the current qualified or nonqualified name of the user object or data type. If the object to be renamed is a column in a table, object_name must be in the form table.column or schema.table.column. If the object to be renamed is an index, object_name must be in the form table.index or schema.table.index.

Quotation marks are only necessary if a qualified object is specified. If a fully qualified name, including a database name, is provided, the database name must be the name of the current database. object_name is nvarchar(776), with no default.
[ @newname = ] 'new_name'

Is the new name for the specified object. new_name must be a one-part name and must follow the rules for identifiers. newname is sysname, with no default.

[ @objtype = ] 'object_type'

Is the type of object being renamed. object_type is varchar(13), with a default of NULL, and can be one of these values.
ValueDescription
COLUMNA column to be renamed.
DATABASEA user-defined database. This object type is required when renaming a database.
INDEXA user-defined index.
OBJECTAn item of a type tracked in sys.objects. For example, OBJECT could be used to rename objects including constraints (CHECK, FOREIGN KEY, PRIMARY/UNIQUE KEY), user tables, and rules.
USERDATATYPEAn alias data type or CLR User-defined Types added by executing CREATE TYPE or sp_addtype.


Return Code Values

0 (success) or a nonzero number (failure)
Remarks

You can change the name of an object or data type in the current database only. The names of most system data types and system objects cannot be changed.


sp_rename automatically renames the associated index whenever a PRIMARY KEY or UNIQUE constraint is renamed. If a renamed index is tied to a PRIMARY KEY constraint, the PRIMARY KEY constraint is also automatically renamed by sp_rename.


sp_rename can be used to rename primary and secondary XML indexes.


Renaming a stored procedure, function, view, or trigger will not change the name of the corresponding object name in the definition column of the sys.sql_modules catalog view. Therefore, we recommend that sp_rename not be used to rename these object types. Instead, drop and re-create the object with its new name.


Renaming an object such as a table or column will not automatically rename references to that object. You must modify any objects that reference the renamed object manually. For example, if you rename a table column and that column is referenced in a trigger, you must modify the trigger to reflect the new column name. Use sys.sql_expression_dependencies to list dependencies on the object before renaming it.


Permissions

To rename objects, columns, and indexes, requires ALTER permission on the object. To rename user types, requires CONTROL permission on the type. To rename a database, requires membership in the sysadmin or dbcreator fixed server roles


Examples

A. Renaming a table

The following example renames the SalesTerritory table to SalesTerr in the Sales schema.



USE AdventureWorks;

GO

EXEC sp_rename 'Sales.SalesTerritory', 'SalesTerr';

GO



B. Renaming a column

The following example renames the TerritoryID column in the SalesTerritory table to TerrID.



USE AdventureWorks;

GO

EXEC sp_rename 'Sales.SalesTerritory.TerritoryID', 'TerrID', 'COLUMN';

GO



C. Renaming an index

The following example renames the IX_ProductVendor_VendorID index to IX_VendorID.



USE AdventureWorks;

GO

EXEC sp_rename N'Purchasing.ProductVendor.IX_ProductVendor_VendorID', N'IX_VendorID', N'INDEX';

GO



D. Renaming an alias data type

The following example renames the Phone alias data type to Telephone.



USE AdventureWorks;

GO

EXEC sp_rename N'Phone', N'Telephone', N'USERDATATYPE';

GO


Monday, January 25, 2010

Get keyCode on keypress in javascript

Add this javascript code:

<script>
function getKey(e)
{
//for internet fix
var k = (window.event) ? event.keyCode : e.keyCode;
alert(k);
}
</script>



html code:

<input type="text" onkeypress="getKey(event)" />

Css Sprites - Basic Information, Generator

A Brief Intro:

CSS Sprites have been a hot topic for a long time now. The fact is that each image on a web page is a separate server request and you can dramatically increase the performance of a page by combining images and reducing that number of requests.


For more information read this artical by Chris Coyier on How to Use CSS Sprites

And another artical by Dave Shea on CSS Sprites: Image Slicing’s Kiss of Death

And if you want to generate your sprite online here's a link: Online Css Sprite Generator

Saturday, January 23, 2010

LINQ Basics, Getting started with LINQ and LINQ Queries

LINQ is a set of extensions to the .NET Framework that encompass language-integrated
query, set, and transform operations. It extends C# and Visual Basic with native
language syntax for queries and provides class libraries to take advantage of these
capabilities.

After two decades, the industry has reached a stable point in the evolution of object-oriented
(OO) programming technologies. Programmers now take for granted features like classes,
objects, and methods. In looking at the current and next generation of technologies,
it has become apparent that the next big challenge in programming technology is
to reduce the complexity of accessing and integrating information that is not natively
defined using OO technology. The two most common sources of non-OO information are
relational databases and XML.

LINQ to SQL provides a runtime infrastructure for managing relational data as objects
without losing the ability to query. Your application is free to manipulate the
objects while LINQ to SQL stays in the background tracking your changes automatically.

All the basic information about LINQ that you like to know(msdn link)
101 LINQ Examples

Diffrenece Between Response.Redirect & Server.Transfer

Response.Redirect

  • It will update the user Url history.
  • Pass value using query string.
  • It is slow compared to Sever.Transfer.
  • It will be used to transfre to the external website.
  • Browser's history updated.
  • Url is changed.
  • It can be used for only aspx & html page.
  • This only get method to post variables from one page to another page. It means that
    we need to give in query string if we want to pass some variables to next page.


Server.Transfer

  • It wont update the user URL history.
  • We cant use querystring here.
  • It is faster than Response.Redirect.
  • It can be used only to transfer to other pages of the same web site.
  • The browser's history is not updated.
  • Url is not changed.
  • Only for aspx page.
  • Server.Transfer ("default.aspx","true") then it wil post all the variable using
    the post method.

Friday, January 22, 2010

The ASCII Code, The ASCII Table



ASCII control

characters


0

NULL

(Null character)

1

SOH

(Start of Header)

2

STX

(Start of Text)

3

ETX

(End of Text)

4

EOT

(End of Transmis.)

5

ENQ

(Enquiry)

6

ACK

(Acknowledgement)

7

BEL

(Bell)

8

BS

(Backspace)

9

HT

(Horizontal Tab)

10

LF

(Line feed)

11

VT

(Vertical Tab)

12

FF

(Form feed)

13

CR

(Carriage return)

14

SO

(Shift Out)

15

SI

(Shift In)

16

DLE

(Data link escape)

17

DC1

(Device control 1)

18

DC2

(Device control 2)

19

DC3

(Device control 3)

20

DC4

(Device control 4)

21

NAK

(Negative acknowl.)

22

SYN

(Synchronous idle)

23

ETB

(End of trans. block)

24

CAN

(Cancel)

25

EM

(End of medium)

26

SUB

(Substitute)

27

ESC

(Escape)

28

FS

(File separator)

29

GS

(Group separator)

30

RS

(Record separator)

31

US

(Unit separator)

127

DEL

(Delete)

 


ASCII printable

characters


32

space

64

@

96

`

33

!

65

A

97

a

34

"

66

B

98

b

35

#

67

C

99

c

36

$

68

D

100

d

37

%

69

E

101

e

38

&

70

F

102

f

39

'

71

G

103

g

40

(

72

H

104

h

41

)

73

I

105

i

42

*

74

J

106

j

43

+

75

K

107

k

44

,

76

L

108

l

45

-

77

M

109

m

46

.

78

N

110

n

47

/

79

O

111

o

48

0

80

P

112

p

49

1

81

Q

113

q

50

2

82

R

114

r

51

3

83

S

115

s

52

4

84

T

116

t

53

5

85

U

117

u

54

6

86

V

118

v

55

7

87

W

119

w

56

8

88

X

120

x

57

9

89

Y

121

y

58

:

90

Z

122

z

59

;

91

[

123

{

60

<

92

\

124

|

61

=

93

]

125

}

62

>

94

^

126

~

63

?

95

_

 

 

 


Extended ASCII

characters


128

Ç

160

á

192

+

224

Ó

129

ü

161

í

193

-

225

ß

130

é

162

ó

194

-

226

Ô

131

â

163

ú

195

+

227

Ò

132

ä

164

ñ

196

-

228

õ

133

à

165

Ñ

197

+

229

Õ

134

å

166

ª

198

ã

230

µ

135

ç

167

º

199

Ã

231

þ

136

ê

168

¿

200

+

232

Þ

137

ë

169

®

201

+

233

Ú

138

è

170

¬

202

-

234

Û

139

ï

171

½

203

-

235

Ù

140

î

172

¼

204

¦

236

ý

141

ì

173

¡

205

-

237

Ý

142

Ä

174

«

206

+

238

¯

143

Å

175

»

207

¤

239

´

144

É

176

¦

208

ð

240

=

145

æ

177

¦

209

Ð

241

±

146

Æ

178

¦

210

Ê

242

=

147

ô

179

¦

211

Ë

243

¾

148

ö

180

¦

212

È

244



149

ò

181

Á

213

i

245

§

150

û

182

Â

214

Í

246

÷

151

ù

183

À

215

Î

247

¸

152

ÿ

184

©

216

Ï

248

°

153

Ö

185

¦

217

+

249

¨

154

Ü

186

¦

218

+

250

·

155

ø

187

+

219

¦

251

¹

156

£

188

+

220

_

252

³

157

Ø

189

¢

221

¦

253

²

158

×

190

¥

222

Ì

254

¦

159

ƒ

191

+

223

¯

255

nbsp

Thursday, January 21, 2010

MooTools and jQuery conflict problem in Internet Explorer, noConflict

When we use MooTools and jQuery together in our page, common problem we found is that some functionality is not working properly for MooTools or jQuery

Sometimes it is hard to find out that the problem is in using both together

The solution is so simple. We have to say jQuery to not to conflict with other libraries.

You have to add jQuery.noConflict() to your jQuery code.


<p>jQuery sets this paragraph's color to red but MooTools sets the border color.</p>
<script type="text/javascript" src="jquery-1.3.js"></script>
<script type="text/javascript">
//no conflict jquery this makes possible to use both library together
jQuery.noConflict();
//jquery stuff
(function($) {
$('p').css('color','#ff0000');
})(jQuery);
</script>
<script type="text/javascript" src="moo1.2.js"></script>
<script type="text/javascript">
//moo stuff
window.addEvent('domready',function() {
$$('p').setStyle('border','1px solid #fc0');
});
</script>


jQuery is namespaced so the $ function is free for MooTools to take hold of. The jQuery code passes jQuery to itself and then we call the argument $, thus jQuery is contained, so to speak.

Obviously including two libraries within the same page is resource-consuming but if it’s acceptable to the project and allows you to implement plugins from each library quickly, this may be a great option for you.

Reset All Settings in Visual Studio 2008


1) Open command prompt

2) Go to location :

C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\

3) Command to Reset Settings:

devenv /resetsettings

Wednesday, January 20, 2010

Best Javascript and Css Compresser - YUI Compressor


Brief Advantages of YUI Compressor


  • Easy to use

  • High compression rate

  • Reliable end results (doesn't mess up the code)



If you are looking for a good compressor for your javascript YUI Compressor is the way to go.

Great compression rate, well tested and in use among many top sites, and well, personally recommended by me.

I've used it for my projects without a single JS error or hiccup. And it has nice documentation.

Note: Although Dan Edwards's packer achieves a better compression rate than YUICompressor, I ran into a few JS errors when using it.

Visitor's Browser Type, IP address and more in ASP

Here is a small code that can help you getting the ip address, browser type, request type and many more things..

<html>
<body>
<p>
<b>You are browsing this site with:</b>
<% Response.Write(Request.ServerVariables("http_user_agent"))%>
</p>
<p>
<b>Your IP address is:</b>
<%Response.Write(Request.ServerVariables("remote_addr"))%>
</p>
<p>
<b>The DNS lookup of the IP address is:</b>
<%Response.Write(Request.ServerVariables("remote_host"))%>
</p>
<p>
<b>Local IP address is:</b>
<%Response.Write(Request.ServerVariables("local_addr"))%>
</p>
<p>
<b>The method used to call the page:</b>
<%Response.Write(Request.ServerVariables("request_method"))%>
</p>
<p>
<b>The server's domain name:</b>
<%Response.Write(Request.ServerVariables("server_name"))%>
</p>
<p>
<b>The server's port:</b>
<%Response.Write(Request.ServerVariables("server_port"))%>
</p>
<p>
<b>The server's software:</b>
<%Response.Write(Request.ServerVariables("server_software"))%>
</p>
</body>
</html>