Latest news
Home » SQL (page 2)

SQL

Export large sql table data to csv using php(socialengine)

//function to download  all users deatails to csv public function downloadcsvAction() { ob_end_clean(); set_time_limit(0); ini_set(‘memory_limit’, ‘2024M’); $this->_helper->viewRenderer->setNoRender(true); $this->_helper->layout->disableLayout(); $query=Engine_Db_Table::getDefaultAdapter()->select() ->from(‘engine4_users’,array(‘user_id’,’email’,’displayname’,’level_id’,’enabled’,’approved’,’intro_page’,’creation_date’)) ->where(‘user_id <> ?’, 1) ->where(‘user_id not in (?)’, array(‘685′,’870′,’948′,’965′,’1031′,’1249′,’1279′,’1283’)) ->where(‘user_id <> ?’, 6); $aResult= $query->query()->fetchAll(); $fileName = “users_”.time().’.csv’; header(‘Content-Type: application/csv’); header(‘Content-Disposition: attachement; filename=”‘.$fileName.'”‘); $f = fopen(‘php://output’, ‘w’) or show_error(“Can’t open php://output”); $n = 0; $line = array(); $array=array(); // foreach ...

Read More »

Relational Operators in sql

Programmers are using number of relational operators for producing required results Commonly used ones are = Equalto < lessthan > greater than <= lessthan or equalto >= greater than or equal to <> IS NOT ! not ^ like -like operator

Read More »

How to see table stucture in SQL

table stucture in SQL SQL>desc <table name> Example: SQL>desc smarttips Name       Null                    Type Id              NOT NULL      NUMBER(2) Name                                   varchar(10)

Read More »

How to ALTER table in SQL

ALTER a table in SQL Use the following commands for add,change,drop table fields in SQL. SQL>AlTER TABLE <Table name> <ADD,DROP,CHANGE> <field name> ALTER TABLE  `test` ADD  `test INT NOT NULL ALTER TABLE  `test` DROP `name` ALTER TABLE  `test` CHANGE  `name`  `student_name` INT( 11 ) NOT NULL

Read More »

How to create a table in SQL

Command or syntax for crating a table in SQL SQL> CREATE TABLE <tablename name>(fieldname datatype(size) PRIMARY KEY); Example:CREATE TABLE STUDENT(stu_number number(2) PRIMARY KEY,stu_name varchar(20));

Read More »