MySQL: Create a table via code

To hand-code a table, or create a bunch of tables in a script, use this: CREATE TABLE `tablename`( `id` INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY, `name` VARCHAR(255) NOT NULL ) You may note the “backticks” which are the little symbol on the same key as the tilde “~”, and are used to note the tablename [...]

SQL: LIKE Searches

There is no pause in there, “LIKE!…searches!” This is a no teeny-bopper zone (unless you want to program stuff, then by all means)! When you know only part of what you’re looking for in a SQL SELECT statement, especially for AJAX auto-complete queries, you will need to employ the all-consuming power of the “LIKE Search” [...]

SQL: Insert Query

The local variables here can be ones you send to your stored procedure, local variables, whatever. The first set of parenthesisW “()” contains the list of fields you want to put data in, like telling someone to stuff a flyer in certain mailboxes (except for that being illegal). The second list is the values or [...]

SQL: Local variables

DECLARE @var1 VARCHAR(50) SET @var1 = ‘hello’ Then you can use it in your SELECT (and other) statements later, like this: SELECT * FROM tablename WHERE welcomemessage = @var1

SQL: While Loop

To repeat a block of code in SQL until a certain condition is reached, you can use a WHILE loop, like this: –DECLARE your vars first DECLARE @var1 INT DECLARE @var2 INT   –the WHILE itself WHILE @var1 > 10 BEGIN @var2 = @var2 + @var1 IF @var2 > 10 BREAK END The IF block [...]