Tag: table

C#

Add new column to database table programmatically

Let’s see how we can add a new column to an existing table in database using c#. SqlConnection Connection = null;   try { Connection = new SqlConnection( "Data Source=" + sql_server_ip_or_hostname + ";" + "Initial Catalog=" + database_name + ";" + "User Id=" + username + ";" + "Password=" + password + ";" + …

Microsoft SQL Server

Get Field Name and Type of Database Table

Today we will see how we can retrieve table’s columns’ names and types. USE mydatabase GO   SELECT column_name, data_type FROM information_schema.columns WHERE TABLE_NAME = ‘mytable’;use mydatabase go SELECT column_name, data_type FROM information_schema.columns WHERE table_name = ‘mytable’;

Microsoft SQL Server, MySQL, Oracle

SQL column name with blank space

Let’s see how we can write queries when a column name contains spaces:   Microsoft Sql Server SELECT [COLUMN Name] FROM TABLE_NAME;SELECT [Column Name] FROM table_name; MySQL SELECT ‘Column Name’ FROM TABLE_NAME;SELECT ‘Column Name’ FROM table_name; Oracle SELECT "Column Name" FROM TABLE_NAME;SELECT "Column Name" FROM table_name;