working on it ...

Filters

Explore Public Snippets

Sort by

Found 8,799 snippets

    public by anand  270  0  3  0

    LENGTH OF CHARACTER, ORDER BY AND LIMIT

    LENGTH OF CHARACTER, ORDER BY AND LIMIT: new_gist_file.sql
    SELECT CITY,LENGTH(CITY) FROM STATION ORDER BY CITY ASC LIMIT 1;
    
    
    SELECT * FROM CUSTOMERS
       ORDER BY (CASE ADDRESS
       WHEN 'DELHI' 	 THEN 1
       WHEN 'BHOPAL' 	 THEN 2
       WHEN 'KOTA' 	 THEN 3
       WHEN 'AHMADABAD' THEN 4
       WHEN 'MP' 	THEN 5
       ELSE 100 END) ASC, ADDRESS DESC;     ###ORDERING IN A PARTICULAR ORDER
       
       
    select * from nobel where winner like 'Sir%' order by yr desc,winner asc
    
    

    public by yourfriendcaspian  330  0  3  0

    PostgreSQL - full-text search configuration

    PostgreSQL - full-text search configuration: pg_search_conf_unaccented.sql
    -- enable extensions
    -- full-text search on postgresql
    CREATE EXTENSION unaccent;
    
    -- languages supported
    CREATE TEXT SEARCH CONFIGURATION fr ( COPY = french );
    ALTER TEXT SEARCH CONFIGURATION fr ALTER MAPPING
    FOR hword, hword_part, word WITH unaccent, french_stem;
    
    CREATE TEXT SEARCH CONFIGURATION en ( COPY = english );
    ALTER TEXT SEARCH CONFIGURATION en ALTER MAPPING
    FOR hword, hword_part, word WITH unaccent, english_stem;
    
    CREATE TEXT SEARCH CONFIGURATION de ( COPY = german );
    ALTER TEXT SEARCH CONFIGURATION de ALTER MAPPING
    FOR hword, hword_part, word WITH unaccent, german_stem;
    
    CREATE TEXT SEARCH CONFIGURATION nl ( COPY = dutch );
    ALTER TEXT SEARCH CONFIGURATION nl ALTER MAPPING
    FOR hword, hword_part, word WITH unaccent, dutch_stem;
    
    CREATE TEXT SEARCH CONFIGURATION da ( COPY = danish );
    ALTER TEXT SEARCH CONFIGURATION da ALTER MAPPING
    FOR hword, hword_part, word WITH unaccent, danish_stem;
    
    CREATE TEXT SEARCH CONFIGURATION fi ( COPY = finnish );
    ALTER TEXT SEARCH CONFIGURATION fi ALTER MAPPING
    FOR hword, hword_part, word WITH unaccent, finnish_stem;
    
    CREATE TEXT SEARCH CONFIGURATION hu ( COPY = hungarian );
    ALTER TEXT SEARCH CONFIGURATION hu ALTER MAPPING
    FOR hword, hword_part, word WITH unaccent, hungarian_stem;
    
    CREATE TEXT SEARCH CONFIGURATION it ( COPY = italian );
    ALTER TEXT SEARCH CONFIGURATION it ALTER MAPPING
    FOR hword, hword_part, word WITH unaccent, italian_stem;
    
    CREATE TEXT SEARCH CONFIGURATION no ( COPY = norwegian );
    ALTER TEXT SEARCH CONFIGURATION no ALTER MAPPING
    FOR hword, hword_part, word WITH unaccent, norwegian_stem;
    
    CREATE TEXT SEARCH CONFIGURATION pt ( COPY = portuguese );
    ALTER TEXT SEARCH CONFIGURATION pt ALTER MAPPING
    FOR hword, hword_part, word WITH unaccent, portuguese_stem;
    
    CREATE TEXT SEARCH CONFIGURATION ro ( COPY = romanian );
    ALTER TEXT SEARCH CONFIGURATION ro ALTER MAPPING
    FOR hword, hword_part, word WITH unaccent, romanian_stem;
    
    CREATE TEXT SEARCH CONFIGURATION ru ( COPY = russian );
    ALTER TEXT SEARCH CONFIGURATION ru ALTER MAPPING
    FOR hword, hword_part, word WITH unaccent, russian_stem;
    
    CREATE TEXT SEARCH CONFIGURATION es ( COPY = spanish );
    ALTER TEXT SEARCH CONFIGURATION es ALTER MAPPING
    FOR hword, hword_part, word WITH unaccent, spanish_stem;
    
    CREATE TEXT SEARCH CONFIGURATION sv ( COPY = swedish );
    ALTER TEXT SEARCH CONFIGURATION sv ALTER MAPPING
    FOR hword, hword_part, word WITH unaccent, swedish_stem;
    
    CREATE TEXT SEARCH CONFIGURATION tr ( COPY = turkish );
    ALTER TEXT SEARCH CONFIGURATION tr ALTER MAPPING
    FOR hword, hword_part, word WITH unaccent, turkish_stem;
    
    CREATE TEXT SEARCH CONFIGURATION usimple ( COPY = simple );
    ALTER TEXT SEARCH CONFIGURATION usimple ALTER MAPPING
    FOR hword, hword_part, word WITH unaccent, simple;
    
    

    public by yourfriendcaspian  322  0  4  0

    How to install MySQL with Python and Django Debian/Derivatives

    #Install Mysql with Python and Django Debian/Derivatives 
    
    #To install we need to have some dependencies in the system for now we will show on
    #Debian and Derivatives.
    
    #But first install updates and MySQL
    
    ```
    $ sudo apt-get update
    $ sudo apt-get upgrade
    ```	
    
    # ** NOTE: ** 
    #Each System has its commands for updating, if your machine is not derived from Debian ** look for them **
    
    ##Install MySQL
    
    ```
    $ sudo apt-get install mysql-server mysql-client
    Passwd for 'root' user: <password>
    ```
    
    #At the end we execute this command to give more security to our BD
    
    ```
    $ mysql_secure_installation
    ```
    
    #Check carefully the changes that will be made, the first question is the passwd for root,
    #IF you want to keep or change it, and continue with other security questions.
    
    ##Create a database and a user for the DB
    
    #Now we will create the DB that will be connected to DJango and a User with Passwd to access it.
    #There are two ways to do this:
    
    ```
    echo "CREATE DATABASE <DATABASENAME>;" | mysql -u root -p
    echo "CREATE USER '<DATABASEUSER>'@'localhost' IDENTIFIED BY '<PASSWORD>';" | mysql -u root -p
    echo "GRANT ALL PRIVILEGES ON <DATABASENAME>.* TO '<DATABASEUSER>'@'localhost';" | mysql -u root -p
    echo "FLUSH PRIVILEGES;" | mysql -u root -p
    ```
    
    #So they should put their passwd of mysql in each line or
    #they can also do it of the following way
    
    ```
    $ mysql -u root -p
    ```
    
    #Enter your passwd and then do the following.
    
    ```
    CREATE DATABASE <DATABASENAME>;
    CREATE USER '<DATABASEUSER>'@localhost IDENTIFIED BY '<PASSWORD>';
    GRANT ALL PRIVILEGES ON <DATABASENAME>.* TO '<DATABASEUSER>'@localhost;
    FLUSH PRIVILEGES;
    exit
    ```
    
    #We Check Dependencies
    #There are only a few dependencies but you have to be sure
    
    ```
    $ sudo apt-get install libmysqlclient-dev python-dev
    ```
    
    #So far it's all just proceed to install pip in our virtual environment or globally
    
    ```
    $ sudo -H pip install mysql-python
    ```
    
    #As you can see now you can create DB and Users for each Django Project

    public by yourfriendcaspian  217  0  3  0

    Create mysql user with specific permissions

    Create mysql user with specific permissions: mysql_grant.sql
    CREATE USER 'joe'@'%' IDENTIFIED BY 'xxxxxx';
    # ALL PRIVILEGES is everything except grant
    GRANT ALL PRIVILEGES ON APP_production_temp.* TO 'joe'@'%'; 
    GRANT SELECT ON APP_production.* TO 'joe'@'%';
    GRANT SELECT ON stats_production.* TO 'joe'@'%';
    
    

    public by snip2code  658  3  4  0

    First Snippet: How to play with Snip2Code

    This is the first example of a snippet: - the title represents in few words which is the exact issue the snippet resolves; it can be something like the name of a method; - the description (this field) is an optional field where you can add interesting information regarding the snippet; something like the comment on the head of a method; - the c
    /* place here the actual content of your snippet. 
       It should be code or pseudo-code. 
       The less dependencies from external stuff, the better! */

    public by sjschmalfeld  3310  9  5  2

    Rename Logical Name Database SQL Server

    Changes the logical name of a database
    // Enter here the actual content of the snippet.            
    
    -- Rename logical names (only needed if restoring from a backup for a Different database):
    ALTER DATABASE MyDatabase 
    MODIFY FILE (NAME = 'OrigDatabase_Data', NEWNAME = 'MyDatabase_data')
    GO
    ALTER DATABASE MyDatabase 
    MODIFY FILE (NAME = 'OrigDatabase_Log', NEWNAME = 'MyDatabase_log')
    GO                        

    public by cwilli34  349  0  3  0

    Set SQL database to single user mode

    Set SQL database to single user mode: database_single_user.sql
    USE master;
    GO
    ALTER DATABASE AdventureWorks2012
    SET SINGLE_USER
    WITH ROLLBACK IMMEDIATE;
    GO
    ALTER DATABASE AdventureWorks2012
    SET READ_ONLY;
    GO
    ALTER DATABASE AdventureWorks2012
    SET MULTI_USER;
    GO
    
    

    public by bobby  157353  2  4  0

    Returns Descriptions for all active Magento products

    Returns Descriptions for all active Magento products: Magento-active-product-descriptions.sql
    SELECT 
        e.entity_id,
        e.sku,
        eav.value AS 'description',
        IF(at_status.value_id > 0,
            at_status.value,
            at_status_default.value) AS `status`
    FROM
        catalog_product_entity e
            JOIN
        catalog_product_entity_text eav ON e.entity_id = eav.entity_id
            JOIN
        eav_attribute ea ON eav.attribute_id = ea.attribute_id
            INNER JOIN
        `catalog_product_entity_int` AS `at_status_default` ON (`at_status_default`.`entity_id` = `e`.`entity_id`)
            AND (`at_status_default`.`attribute_id` = '89')
            AND `at_status_default`.`store_id` = 0
            LEFT JOIN
        `catalog_product_entity_int` AS `at_status` ON (`at_status`.`entity_id` = `e`.`entity_id`)
            AND (`at_status`.`attribute_id` = '89')
            AND (`at_status`.`store_id` = 1)
    WHERE
        ea.attribute_code = 'description'
            AND IF(at_status.value_id > 0,
            at_status.value,
            at_status_default.value) = 1
    LIMIT 9999
    
                

    public by JulioTrujillo  7767  0  4  0

    Anonimous block

    SQL
    cl scr
    set lin 200
    SET SERVEROUTPUT ON
    SET TERMOUT ON
    
    DECLARE 
    
    BEGIN
    
    END;
    /

    public by sjschmalfeld  298721  1  4  1

    Kill Connections to a Database SQL Server

    sql
    // KILL CONNECTIONS TO A DATABASE
    
    USE [master]
    GO  
    
    DECLARE @kill varchar(8000) = '';  
    SELECT @kill = @kill + 'kill ' + CONVERT(varchar(5), session_id) + ';'  
    FROM sys.dm_exec_sessions
    WHERE database_id  = db_id('MyDB')
    
    EXEC(@kill);
    • Public Snippets
    • Channels Snippets