Posts

Showing posts with the label Sql Example

Alter User Mysql Code Example

Example 1: mysql create user CREATE USER 'user' @'localhost' IDENTIFIED BY 'password' ; GRANT ALL PRIVILEGES ON * . * TO 'user' @'localhost' ; FLUSH PRIVILEGES ; Example 2: alter user mysql native password ALTER USER 'root' @'localhost' IDENTIFIED WITH mysql_native_password BY '<password>' ; Example 3: change mysql password from command line ALTER USER 'root' @'localhost' IDENTIFIED BY 'New-Password' ; Example 4: alter user root mysql ALTER USER 'root' @'localhost' IDENTIFIED BY 'newPassword' ; Example 5: mysql set password for user # `SET PASSWORD FOR <user> = PASSWORD('<plaintext_password>')` is deprecated SET PASSWORD FOR < user > = '<plaintext_password>' ; FLUSH PRIVILEGES ; Example 6: change user mysql [ madegow @fedora20 ~ ] $ mysql - u root - p Enter password: . . . MariaDB ...

Create User With All Privileges And Password Mysql Code Example

Example 1: mysql add user with all privileges CREATE USER 'newuser' @'localhost' IDENTIFIED BY 'password' ; GRANT ALL PRIVILEGES ON * . * TO 'newuser' @'localhost' ; FLUSH PRIVILEGES ; Example 2: mysql add user with all privileges # First Login mysql shell.. sudo mysql - u root - p CREATE USER 'username' @'localhost' IDENTIFIED BY 'P4ssW0rd' ; GRANT ALL PRIVILEGES ON * . * TO 'username' @'localhost' ; FLUSH PRIVILEGES ;

1046, 'No Database Selected' Code Example

Example: mariadb error 1046 (3d000) no database selected USE database_name ;

Count Number Of Times A Value Appears Sql Code Example

Example: sql count how many times a value appears * For Example - You have a table called t1 & in that table you want to know how many times "ABC" name occured . So your query will be . select name , count ( * ) as total FROM t1 GROUP BY name

A Sql Query Automatically Eliminates Duplicates Code Example

Example 1: sql delete duplicate -- Oracle DELETE films WHERE rowid NOT IN ( SELECT min ( rowid ) FROM films GROUP BY title , uk_release_date ) ; Example 2: how to query without duplicate rows in sql SELECT DISTINCT col1 , col2 . . . FROM table_name where Condition ; Example 3: how to remove duplicate in sql Distinct : helps to remove all the duplicate records when retrieving the records from a table . SELECT DISTINCT FIRST_NAME FROM VISITORS ; Example 4: sql delete duplicate rows but keep one # Step 1: Copy distinct values to temporary table CREATE TEMPORARY TABLE tmp_user ( SELECT id , name FROM user GROUP BY name ) ; # Step 2: Remove all rows from original table DELETE FROM user ; # Step 3: Remove all rows from original table INSERT INTO user ( SELECT * FROM tmp_user ) ; # Step 4: Remove temporary table DROP TABLE tmp_user ; Example 5: sql query to delete duplicate records --ID should be pri...

Alter Table Modify Column Oracle Code Example

Example 1: alter table column size oracle ALTER TABLE tablename MODIFY fieldname VARCHAR2 ( 100 ) ; Example 2: alter table oracle ALTER TABLE tablename MODIFY columnname varchar2 ( 100 ) Example 3: orcale sql change column type ALTER TABLE table_name MODIFY column_name action ; Example 4: oracle alter table add column ALTER TABLE table_name ADD column_name data_type constraint ;

Alter Table Mysql Add Column After Code Example

Example 1: mysql alter table add column ALTER TABLE vendors ADD COLUMN phone VARCHAR ( 15 ) AFTER name ; Example 2: add column in mysq ALTER TABLE Table_name ADD Email varchar ( 255 ) ; Example 3: insert column after column mysql ALTER TABLE tbl_name ADD COLUMN new_column_name VARCHAR ( 15 ) AFTER existing_column_name ; Example 4: add column in mysq ALTER TABLE Table_name ADD name_column INT ( 255 ) ; Example 5: mysql alter table add column ALTER TABLE table ADD [ COLUMN ] column_name column_definition [ FIRST | AFTER existing_column ] ; Example 6: mysql alter table add column ALTER TABLE table ADD [ COLUMN ] column_name column_definition [ FIRST | AFTER existing_column ] ;

Convert Double To Int In Java Code Example

Example 1: int to double java Double d = new Double ( i ) ; //first way Double d2 = Double . valueOf ( i ) ; //second way Example 2: how to change double to int in java class Scratch{ public static void main ( String [ ] args ) { double decimal = 5.7 ; System . out . println ( ( int ) decimal ) ; //casting System . out . println ( Math . round ( decimal * 10 ) / ( double ) 10 ) ; //Math.round() System . out . println ( decimal % 1 ) ; // modulus System . out . println ( Integer . parseInt ( String . valueOf ( decimal ) . substring ( 0 , String . valueOf ( decimal ) . indexOf ( "." ) ) ) ) ; // .substring() } } Example 3: java casting to int //In java, you can cast to any primitive type by putting (primitiveType) //before whatever you're casting to. private static int myInt = ( int ) myDouble ; Example 4: convert double into integer class DoubleToInt { public static void main ( String...

Count Rows SQL Code Example

Example 1: sql query to get the number of rows in a table SELECT COUNT ( * ) FROM tablename Example 2: sql count /*COUNT(column_name) will return the number of rows from the column that are not NULL*/ SELECT COUNT ( column_name ) FROM table_name ; /*COUNT(*) will return the number of rows from the table*/ SELECT COUNT ( * ) FROM table_name ; Example 3: To count number of rows in SQL table SELECT count ( * ) FROM information_schema . columns WHERE table_name = 'Your_table_nale' ; Example 4: how to count number of rows in sql SELECT COUNT ( * ) FROM dbo . bigTransactionHistory ;

Add Id Autoincrement Column To Existing Table Mysql Code Example

Example 1: add auto_increment column to existing table mysql ALTER TABLE ` users ` ADD ` id ` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ALTER TABLE ` users ` ADD ` id ` INT NOT NULL AUTO_INCREMENT UNIQUE FIRST Example 2: mysql add auto increment id existing table ALTER TABLE ` users ` ADD ` id ` INT NOT NULL AUTO_INCREMENT PRIMARY KEY

Alter Table Add Column Query Code Example

Example 1: sql add column ALTER TABLE Customers ADD Email varchar ( 255 ) ; Example 2: alter table add column ALTER TABLE table_name ADD column_name datatype ;

C# Linq Select Where In List Code Example

Example 1: c# linq select from object list // this will return the first correct answer, // or throw an exception if there are no correct answers var correct = answers . First ( a = > a . Correct ) ; // this will return the first correct answer, // or null if there are no correct answers var correct = answers . FirstOrDefault ( a = > a . Correct ) ; // this will return a list containing all answers which are correct, // or an empty list if there are no correct answers var allCorrect = answers . Where ( a = > a . Correct ) . ToList ( ) ; Example 2: linq where in list var allowedStatus = new [ ] { "A" , "B" , "C" } ; var filteredOrders = orders . Order . Where ( o = > allowedStatus . Contains ( o . StatusCode ) ) ; Example 3: linq query select where c# var queryLondonCustomers = from cust in customers where cust . City = = "London" select cust ...

Alter Table Delete Column Sql Code Example

Example 1: alter table delete column ALTER TABLE "table_name" DROP "column_name" ; Example 2: sql delete column Deletes a column from a table . Example: Removes the first_name column from the users table . ALTER TABLE users DROP COLUMN first_name

Add Column Mysql After Another Column Code Example

Example: insert column after column mysql ALTER TABLE tbl_name ADD COLUMN new_column_name VARCHAR ( 15 ) AFTER existing_column_name ;

Alter Table & Drop Primary Key Constraint Oracle Code Example

Example: drop primary key oracle -- Dropping Using alter ALTER TABLE table_name DROP CONSTRAINT constraint_name ;

Create Database Mysql Utf8 Code Example

Example 1: create database mysql utf8 CREATE DATABASE mydatabase CHARACTER SET utf8 COLLATE utf8_general_ci ; Example 2: mysql create database utf8 CREATE DATABASE mydatabase CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci ; Example 3: mysql create database charset utf8mb4 CREATE DATABASE mydatabase CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci ;

Adddate Sql Code Example

Example: sql server current date minus 5 years SELECT GETDATE ( ) 'Today' , DATEADD ( day , - 2 , GETDATE ( ) ) 'Today - 2 Days' SELECT GETDATE ( ) 'Today' , DATEADD ( dd , - 2 , GETDATE ( ) ) 'Today - 2 Days' SELECT GETDATE ( ) 'Today' , DATEADD ( d , - 2 , GETDATE ( ) ) 'Today - 2 Days'

Alterning Cumn In Sql Code Example

Example 1: sql add column ALTER TABLE Customers ADD Email varchar ( 255 ) ; Example 2: alter table add column ALTER TABLE table_name ADD column_name datatype ;

Create View Join Mysql Code Example

Example 1: create view mysql CREATE VIEW ` general_v_movie_rentals ` AS SELECT mb . ` membership_number ` , mb . ` full_names ` , mo . ` title ` , mr . ` transaction_date ` , mr . ` return_date ` FROM ` movierentals ` AS mr INNER JOIN ` members ` AS mb ON mr . ` membership_number ` = mb . ` membership_number ` INNER JOIN ` movies ` AS mo ON mr . ` movie_id ` = mo . ` movie_id ` ; Example 2: mysql view from multiple tables CREATE VIEW V AS ( SELECT i . country , i . year , p . pop , f . food , i . income FROM INCOME i LEFT JOIN POP p ON i . country = p . country LEFT JOIN Food f ON i . country = f . country WHERE i . year = p . year AND i . year = f . year ) ;

Count Days Between Two Dates In Sql Code Example

Example: sql get number of days between two dates DATEDIFF ( DAY , '1/1/2011' , '3/1/2011' )