Rename Local Database tables in SQL with Visual Studio 2008 - sql-server-2008

I have created a local database db.mdf in VS2010 asp.net website. In there are a few tables.
Now I need to rename the tables. But query designer doesn't let me. How do I rename those tables?

In Server Explorer, right-click the table you want to rename and choose Open Table Definition from the shortcut menu.
The table opens in the Table Definition window of Table Designer.
2. Right-click the table in the Table Definition window and choose Properties from the shortcut menu.
3. In the field for the Name value in the Properties window, type a new name for the table.
To cancel this action, press the ESC key before leaving this field.
From the File menu choose Save table name.

Rename database tables in Visual Studio:
Server Explorer
Right click on the tables
Click the Edit Table Schema

The answers did not work for me in Visual Studio 2017. The Table field is locked for some reason.
What worked for me is the following. In the T-SQL tab change the entry
CREATE TABLE [dbo].[Table] (
to
CREATE TABLE [dbo].[NewTableName] (
Then select Update (top-left). It worked for me.

Related

Navicat rename field in model and sync to server without drop

I created a model from a database schema's tables. It's working correctly, but when I rename a column in a table and after that I sync to the server. Navicat recognize the changes and show the SQL queries which needed to be executed. The queries are the following:
disable foreign key checks
drop indexes
create column with new name
drop old column
recreate previously dropped indexes with the currently created column
enable foreign key checks
How can I force Navicat to not drop columns, just rename them?
Thanks in advance, kukko.
Have a look at object editors in dbForge Studio for MySQL. There is possibility to rename the field with dependent object modifications.
Here it is another simple way to rename the column:
select column in Database Explorer
press F2 (Rename command) and enter new name
choose Rename or Refactor (with dependent objects modifications)
By simply executing the statement to rename the column:
ALTER TABLE your_tablename CHANGE column_name new_name datatype other_options_like_nullable;
For example:
ALTER TABLE myTable CHANGE badname newname INT NOT NULL DEFAULT 0;

Unable to refresh a local table created from linked table

I am new to access database.
I created a linked table (linked to an excel file)
I them created a local table which is just a filtered table from the linked table. (same table just filtered for some records.)
The issue I am running into is that I am not able to refresh this local filtered table. The steps I am following are :
Refresh linked table using 'linked table manager'
Refresh the local table (filtered version of linked table) using linked table manager and the refresh button in the menu bar.
While my linked table gets refreshed, this filtered table does not get refreshed.
Can someone suggest what I can do?
Thanks in advance
You might want to use a query rather then your local, filtered, table.
If you want to keep your current structure try this
Create -> Query Design -> click on SQL on the bottom right -> paste the following code in
SELECT * INTO local_filtered_table
FROM linked_table
WHERE <put your conditions here>;
Then run this query each time you update your linked table.
Or you can do as Rene suggested and just make a query instead of a local table which would look something like this.
SELECT *
FROM linked_table
WHERE <put your conditions here>;

AUTOINCREMENT not automatically adding values in Mysql Workbench IDE

I am learning to use MYSQL-Workbench for inserting data into tables
My Problem::
I have two columns one for Sl_no and one for Name
Sl_no is the primary key which has auto increment checked as shown in
snapshot-1
If you look at Snapshot-2 auto_increment is not automatically
incremented when i keep adding the values
should i need to enable any option for this ?
Because Using the IDE should automatically add values(Since Sl_NO has
autoincrement enabled) but it is not doing so
I have to manually add it one after another
Snapshot-1
Snapshot-2
How can i resolve this ?
{EDIT}
I am using Windows-7 OS
As you can see i am clicking the marked area in the pic to apply
changes, but nothing is happening.
Should i need to enable any settings
UPDATE: It wasn't apparent right away that you're doing this from model and not directly in your db table.
To create your schema from model you need to do Forward Engineering and in the dialog choose Generate INSERT Statements for Tables.
Then go to the object browser in your MySQL connection, not your model. Fire select statement in query window or choose from context menu Select Rows - LIMIT 1000 and you'll see that your sl_no column is populated as expected.
BTW both mac and windows interfaces are identical.
Original answer:
You forgot to commit your changes by clicking Apply
And after reviewing the change script click Apply again.
After that you'll see your auto_increment column values populated

Script Relationships only SQL Server

Is there a way in SQL server to generate a script to re-create all the foreign key constraints and relationships? Basically I need to delete all relationships and then need to re-script them against the database.
Thanks in advance
For MS SQL Server here you have a full script with details and comments. And also you can use the SMSS to generate a create script of a table with all its necesary details. But this will do the work for only one table, if you need to do it for all tables and there are a lot, it could be a pain right there.
For MySQL, in case you needed it check this link
In SQL Server Management Studio, you can select see your tables. You can walk through 1 by 1. Press right click on the table -> Script Table As -> DROP And CREATE TO.
With this the Studio will generate the drop constraints and alter table add constraints in a new query window.

SQL Server 2008 management studio drop tables warning?

Why does SQL server 2008 always warn about needing to drop tables to rename columns? I was under impression this was not required unless it was a key. If I change a column from null to not null even if is not a key field it wants to drop table and all relations.
If you're editing the table in the designer then it's the designer that is being pedantic. Try changing (unchecking) these options:
Tools > Designers > Prevent saving changes that require table re-creation
The designer still throws an warning dialog after unchecking that but there is also this option to uncheck:
Tools > Designers > Warn about tables affected
I believe the reason the designer has to drop tables to rename columns is because there is no SQL command to do that, and what it does instead is copy the table's data into a temp table, drop the table, create a new table with the altered column name and copy the data into it.